采取以下代码:
function animateTo(parent) {
this.parent = $('#' + parent);
console.log(this.parent)
this.animator = function () {
this.parent.animate({
scrollTop: 5
}, 5);
}
}
test = new animateTo('data');
test.animator;
第一个console.log
在控制台中显示了完整的对象,但是当我尝试运行时this.parent.animate
出现错误:
Uncaught TypeError: Object [object global] has no method 'animate' animator.js:60
(anonymous function
谁能解释这是为什么?我试过this.parent.selector
了,我得到了正确的结果,但是如果我尝试调用 animate 方法,我会得到那个错误。