我正在为我的插件使用jquery 样板模板。我需要从这个插件传递一些回调。这个回调需要是一些带有偏移坐标的变量。
var coordinates = {
x: x2, y: y2
};
我尝试像这样委托这个回调:
;(function ($, window, document) {
/* 'use strict'; */
// default options
var name = "plugin",
defaults = {};
// constructor
function plugin (options, callback) {
this.settings = $.extend({}, defaults, options);
this.init();
this.callback = callback;
}
plugin.prototype = {
init: function () {
var offset = $(this).offset(),
x2 = (e.pageX - offset.left),
y2 = (e.pageY - offset.top);
$(document).on('mouseup', function() {
var coordinates = {
x: x2, y: y2
};
this.callback(coordinates);
});
}
};
// initialize
$.fn[name] = function (options, callback) {
return this.each(function() {
if (!$.data(this, "plugin_" + name)) {
$.data(this, "plugin_" + name, new plugin(options, callback));
}
});
};
})(jQuery, window, document);
我有一个错误,回调不是这个对象的方法。有人可以帮忙吗?