내 클래스 PostsPager
의 생성자에서 @page
의 기본값을 0으로 설정 한 다음 렌더링을 호출합니다. 그러나 render를 입력하면 @page가 정의되지 않습니다. 왜 이럴 수 있니?coffeescript 인스턴스 변수가 정의되지 않았습니다.
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);
};
'new PostsPager()' – Chris