Jan*_*Jan 5 javascript inheritance prototype object-create
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
var o1 = {};
o1.init = function(){
alert('o1');
};
var o2 = Object.create(o1);
o2.init = function(){
// how would I call my ancessors init()?
alert('o2');
};
o2.init();
Run Code Online (Sandbox Code Playgroud)
也许这过于简单化了您\xe2\x80\x99想要完成的任务...将 o1.init() 放在 o2 init 函数中会起作用吗?
\n\no2.init = function(){\n // how would I call my ancessors init()?\n alert(\'o2\');\n o1.init();\n};\n
Run Code Online (Sandbox Code Playgroud)\n\n出于好奇,“ancessors”是“ancestor\xe2\x80\x99s”的拼写错误,还是“ancessors”在这里有特定的含义?您的意思是 o2\xe2\x80\x99s“父”对象吗?
\n