Forum

I can extend module or override methods of modules?

06 October 2017 14:29
Hi guys.

I can extend module or override methods of modules?.

example:
original module anchors.js have this:
exports.append = function(){ console.log("foo bar") }

my custom append method for overwriting the original module anchors.js:
exports.append = function(){ console.log("hello world") }


The main idea is not to modify the original modules of blend4web.

How?. Thanks.
12 October 2017 15:25
Hi, you can create a special module for this purpose and execute it prior to the other app modules:

b4w.register("overwrite_b4w", function(exports, require) {

var m_anchors = require("anchors");
var m_anim = require("animation");
var m_ver = require("version");

exports.init = function() {
    m_anchors.append = function(){ console.log("hello world") };
    m_anim.append = function(){ console.log("hello world") };
}
});
// start application with overriding the original modules
b4w.require("overwrite_b4w").init();



// register and then execute the main app module
b4w.register("my_project_main", function(exports, require) {
    ....
});
b4w.require("my_project_main").init();
17 October 2017 11:22
Reply to post of user Ivan Lyubovnikov
Hi, you can create a special module for this purpose and execute it prior to the other app modules:

b4w.register("overwrite_b4w", function(exports, require) {

var m_anchors = require("anchors");
var m_anim = require("animation");
var m_ver = require("version");

exports.init = function() {
    m_anchors.append = function(){ console.log("hello world") };
    m_anim.append = function(){ console.log("hello world") };
}
});
// start application with overriding the original modules
b4w.require("overwrite_b4w").init();



// register and then execute the main app module
b4w.register("my_project_main", function(exports, require) {
    ....
});
b4w.require("my_project_main").init();

Thank you very much Ivan, I'll prove it
 
Please register or log in to leave a reply.