这不起作用,我不知道如何解决它
function bar() {...}
function foo() {
this = new bar();
this.newfunction = function() {...};
this.newvalue = "foobar";
}
var foobar = new foo();
提前致谢,
这不起作用,我不知道如何解决它
function bar() {...}
function foo() {
this = new bar();
this.newfunction = function() {...};
this.newvalue = "foobar";
}
var foobar = new foo();
提前致谢,
不要this
用来表示另一个对象。
function bar() {...}
function foo() {
var bar = new bar();
bar.newfunction = function() {...};
bar.newvalue = "foobar";
}
var foobar = new foo();
你想继承自bar
吗?call
然后你可以使用(或)借用它的构造函数和它自己的所有属性apply
:
function bar() {...}
function foo() {
bar.call(this);
this.newfunction = function() {...};
this.newvalue = "foobar";
}
var foobar = new foo();