function extend(o, p) {
for(prop in p) {
o[prop] = p[prop];
}
return o;
}
function o() {};
function p(){};
p.name='caicai';
p.show=function(){ alert(this.name);};
p.show(); // output p
extend(o, p);
o.show(); // output o
why the “output” in here? why not to output ‘caicai’.
function extend(o, p) {
for(prop in p) {
o[prop] = p[prop];
}
return o;
}
function o() {};
function p(){};
p.poo='caicai';
p.show=function(){ alert(this.poo);};
p.show(); // output 'caicai'
extend(o, p);
o.show(); // output 'caicai'
BUT in here ?
why the “output” in here? why not to output ‘caicai’.
First: This is not related to the
extendfunction.oandpare functions.Function.name[MDN] is a non-standard property and cannot be overridden.Example:
If you’d declare
oandpas objects, then it would work: