var Logistics = function () {}
Logistics.prototype.addItem = function () {
console.log("item added");
}
(function(){
// Place the above code underneath my comment
// We now get the desired result Why?
console.log("inside internal module");
var myLogistics = new Logistics();
var originalAddItem = myLogistics.addItem;
myLogistics.addItem = function () {
originalAddItem.apply(this,[]);
console.log("another item added");
}
myLogistics.addItem();
}());
预期的控制台输出: -
内部模块内部
项目已添加
另添加了一项
实际控制台输出
内部模块内部
未捕获的TypeError:无法读取未定义的属性“apply”
仅供参考:如果没有人,我会在5小时内发布答案