在我的类的构造函数中,我PostsPager
将默认值设置@page
为 0,然后调用 render。但是,当我输入渲染时,@page 现在是未定义的。为什么会这样?
class PostsPager
contructor: (@page=0)->
render()
$(window).scroll(@check)
check: =>
if @nearBottom()
@render
render: =>
alert @page # @page = undefined
笏
编辑
编译好的 JS
PostsPager = (function() {
function PostsPager() {
this.renderPosts = __bind(this.renderPosts, this);
this.nearBottom = __bind(this.nearBottom, this);
this.render = __bind(this.render, this);
this.check = __bind(this.check, this);
}
PostsPager.prototype.contructor = function(page) {
this.page = page != null ? page : 0;
this.render();
return $(window).scroll(this.check);
};
PostsPager.prototype.check = function() {
if (this.nearBottom()) {
return this.render;
}
};
PostsPager.prototype.render = function() {
alert(this.page);
this.page++;
$(window).unbind('scroll', this.check);
return $.getJSON($('#feed').data('json-url'), {
page: this.page
}, this.renderPosts);
};