백본에서 기능을 비공개로 설정하여 모델 자체에만 노출되고 this
에 액세스 할 수있는 방법이 있습니까?backbone.js 모델에 개인 기능을 추가하는 방법은 무엇입니까?
어떻게 updateTime
을 비공개로 설정할 수 있습니까?
var Timeline = Backbone.Model.extend({
url: 'servertime/',
start: function(){
this.fetch({
success: function(timeline, response){
timeline.updateTime();
setInterval(function() {
timeline.updateTime();
}, 60 * 1000);
}
});
},
updateTime: function(){ //How can I make this private?
this.time = ...
}
});
이 예는 'updateTime'이 타임 라인 메소드가 아니며 'this'가 잘못된 컨텍스트를 갖고 있기 때문에 잘못되었습니다. – masylum
당신이 맞습니다. 나는 서두르다, 나는 지금 나의 예를 편집했다. – alessioalex
'updateTime.call (timeline)'에주의를 기울여서 적절한 문맥이'updateTime'에 전달되도록하는 것이 중요합니다. –