yes, it do the work actually.
see the attached file, decompress, and try:
[root@localhost home]$ cd test/
[root@localhost test]$ node base.model.test.js
model.db is defined
model.extend is defined
model2.db is defined
model2.myCustomModelMethod is defined
[root@localhost test]$ cat base.model.test.js
var Model = require("../models/Base"),
dbMockup = {};
function test1() {
var model = new Model(dbMockup);
if (model.db) {
console.log("model.db is defined");
}
if (model.extend) {
console.log("model.extend is defined");
}
}
function test2() {
var model = new Model(dbMockup);
var OtherTypeOfModel = model.extend({
myCustomModelMethod : function() {}
});
var model2 = new OtherTypeOfModel(dbMockup);
if (model2.db) {
console.log("model2.db is defined");
}
if (model2.myCustomModelMethod) {
console.log("model2.myCustomModelMethod is defined");
}
}
test1();
test2();
【 在 XeCycle (据说是小 X) 的大作中提到: 】
: does this code actually work??? Child is not a new function but the
: original function, and code below just mutates the original function
--
修改:saynothing FROM 218.108.104.*
FROM 218.108.104.*
附件(889B) nodejs_example.tar.gz