我讀的代碼的一部分關於創建於angularjs裏面有服務手段,我不明白是什麼「這個」在這種情況下(this.uploadFile = function (files)
)什麼「這」服務
recipesApp.service('uploadsService', function ($http) {
var code = '';
var fileName = '';
this.uploadFile = function (files) {
var fd = new FormData();
//Take the first selected file
fd.append("image", files[0]);
var promise = $http.post('/uploads/uploadFile.json', fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).then(function (response) {
code = response.data.code;
fileName = response.data.fileName;
return{
code: function() {
return code;
},
fileName: function() {
return fileName;
}
};
});
return promise;
};
});
問題是重複的。 查看回答:http://stackoverflow.com/a/4196018/1209020 – Ryan
也這個帖子http://stackoverflow.com/questions/3127429/javascript-this-keyword –