!对象为什么无法调用子函数
求救!对象为什么无法调用子函数
代码如下
cropper是ImageCropper赋予的对象,我想通过cropper调用loadImage()函数但是无法成功这是为什么?
------解决方案--------------------
代码没问题,请确定是否是先调用init方法,初始化cropper之后再调用onPhotoURISuccess
代码如下
(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
------解决方案--------------------
代码没问题,请确定是否是先调用init方法,初始化cropper之后再调用onPhotoURISuccess