87,901
社区成员
发帖
与我相关
我的任务
分享
window.onload = function() {
function Base() {
this.elements = [];
}
Base.prototype.getId = function(id) {
this.elements.push(document.getElementById('a'));
alert(this); //这行的this
};
Base.getId('a');
};
function test() {
console.log(this.x);
}
var o = {};
o.x = 1;
o.m = test;
o.m();
test();
运行一下就大概理解了。
window.onload = function() {
function Base() {
this.elements = [];
}
Base.prototype.getId = function(id) {
this.elements.push(document.getElementById('a'));
alert(this); //这行的this
};
var base = new Base();
base.getId('a');
};
要new!