이 바로 "이"ImageCarousel 클래스 내부 바르를 참조 사용하기위한저는 "this"를 JavaScript에서 올바르게 사용하고 있습니까?
ImageCarousel = (function() {
var currentIndex, imageManager, imagesVO, jsonPath, values;
currentIndex = null;
jsonPath = "json/images.json";
imagesVO = [];
values = null;
imageManager = null;
function ImageCarousel() {
this.loadJson();
}
ImageCarousel.prototype.loadJson = function() {
var _this = this;
return $.ajax(jsonPath, {
success: function(data, status, xhr) {
console.log("yea " + data);
_this.currentIndex = 0;
_this.imagesVO = data.images;
_this.imageManager = new ImageManager(data.images);
_this.imagesCount = _this.imagesVO.length;
_this.switchToImage(_this.currentIndex);
$('#next').click(function() {
_this.currentIndex = _this.incrementIndexByOne(_this.currentIndex);
return _this.switchToImage(_this.currentIndex);
});
return $('#prev').click(function() {
_this.currentIndex = _this.decrementIndexByOne(_this.currentIndex);
return _this.switchToImage(_this.currentIndex);
});
},
error: function(xhr, status, err) {
return $('#imageHolder').html("problem loading the json file, </br>make sure you are running this on your local server");
},
complete: function(xhr, status) {}
});
};
내가 나는 내 코드? 그 물건들을 공개하니? 그렇다면 어떻게 그들을 비공개로 유지할 수 있습니까?
어떻게 'this'를 사용하고 싶습니까? 'this'와 그 중 많은 것들을 사용하는 몇 가지 방법이 있습니다. 개인 정보는 노출시키지 않고 만들 수 있습니다. 'this '에 추가하면 노출 된 것입니다. – Halcyon
'_this' 대신에'var'을 사용하지 않으셨습니까? – Alexander