var Animal = {
newInstance: function(type) {
return {
type: type,
template: (function(type) {
return $('.item[type="' + type + '"]', "#template").clone(false);
})(this.type)
};
}
};
如上。this每次都是引用Window,请问怎么样解决?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
或者
这里为什么要用this?,如果你要使用newInstance传进来的值,直接type就好,无需加this。
以下是自执行的表达式:
this引用的不是window对象,是Animal对象啊。
由于Animal对象没有定义type属性,所以才会发生错误