代码如下(function(scope){
var ImageCropper = function(width, height, cropWidth, cropHeight)
{
this.width = width;
this.height = height;
this.cropWidth = cropWidth;
this.cropHeight = cropHeight;

this.image = null;
this.imageCanvas = null;
this.imageContext = null;
this.imageScale = 1;
this.imageRotation = 0; this.canvas = null;
this.context = null;
this.previews = [];
}scope.ImageCropper = ImageCropper;ImageCropper.prototype.loadImage = function(file)
{
alert("1");
var reader = new FileReader();
var me = this;
reader.readAsDataURL(file);
reader.onload = function(evt)
{
if(!me.image) me.image = new Image();
me.image.onload = function(e){me._init()};
me.image.src = evt.target.result;
}}  })(window);
var cropper;
function init(){
cropper = new ImageCropper(300, 300, 180, 180);
}  
function onPhotoURISuccess(imageURI) {
cropper.loadImage(imageURI);
}cropper是ImageCropper赋予的对象,我想通过cropper调用loadImage()函数但是无法成功这是为什么?对象函数JavaScript

解决方案 »

  1.   

    代码没问题,请确定是否是先调用init方法,初始化cropper之后再调用onPhotoURISuccess
      

  2.   

    解决问题了,我用window.onload=init()就好了,谢谢
      

  3.   

    解决问题了,我用window.onload=init()就好了,谢谢。。window.onload = init()我可以说你这个代码其实一点意义都没有么window.onload = 必须是一个函数,你写的init(),这样是将init方法的返回结果赋值给了window.onload,虽然看起来init方法执行了,但我想应该跟你实际的想法不一样吧。