// file 1
function augment() {
this.monkey = "monkey";
}
// file 2
function augmentMore() {
this.patch = "patch";
}
// file 3
var o = {};
augment.call(o);
augmentMore.call(o);
console.log(o.monkey + o.patch);
Monkey patching works. partial classes can work by convention. For example consider this convention.
// file main
function SomeObject() {
for (var i = 0, ii = SomeObject.Partial.length; i < ii; i++) {
SomeObject.Partial[i].apply(this, arguments);
}
}
SomeObject.Partial.SomeName = function() {
...
}
// file extra
SomeObject.Partial.SomeOtherName = function() {
...
}
JavaScript is surprisingly powerful. Was there a specific example you were looking for?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…