1
krazy 2012-03-07 18:08:47 +08:00
var self = this;
self.isSuccessful |
2
tearsinchina OP |
3
tearsinchina OP |
4
tearsinchina OP @krazy 还有个问题。我定义了个方法,像这样
uploadify.prototype.showWrongMessage =function(file,msg){ } onUploadError: function (file, errorCode) { switch (errorCode) { case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: self.showWrongMessage(file, 'size or type is wrong'); break; case SWFUpload.UPLOAD_ERROR.IO_ERROR: self.showWrongMessage(file, 'size or type is wrong'); break; } }, 提示 "self.showWrongMessage is not a function",请问是为什么 |
5
eric_zyh 2012-03-07 18:35:11 +08:00
1.通过原型(prototype)拓展的方法,对于不同对象会有不同的this。
2.this.isSuccessful = false; 是定义在uploadify,对象的作用域并没有isSuccessful属性 3."self.showWrongMessage is not a function",如果showWrongMessage是用prototype定义的,这个时候就要用 this.showWrongMessage了。 |
6
tearsinchina OP |
7
tuoxie007 2012-03-07 20:37:55 +08:00 via iPhone
想知道this是什么,看看这个吧, http://tuoxie.me/blog/javascript-this-object-bind/
|