【发布时间】:2013-02-17 16:24:46
【问题描述】:
我希望能够使用对象的成员变量:
function Upload(file, filename, id){
this.file=file
this.filename=filename
this.id=id;
};
Upload.prototype.displayImage = function(btn){
$.canvasResize(file,
{
width: 160,
height: 0,
crop: false,
quality: 100,
callback: function (data)
{
$('#'+btn).css("background", "url("+data+")")
}
});
};
我像这样访问对象和方法:
var upload = new Upload(frontPic, frontPicName, id);
upload.displayImage("btnFrontUploadShow");
但是我得到了错误:
ReferenceError: file is not defined
$.canvasResize(file,
为什么不能在displayImage方法中使用file变量,如何声明displayImage才能使用file变量?
【问题讨论】:
-
你要使用
this.file -
更一般地说,所有实例变量都需要以
this.something访问。
标签: javascript oop object methods