【发布时间】:2015-10-18 18:55:56
【问题描述】:
;(function($) {
var Sanbox = {
init: function(options, elem) {
self = this;
// combine default options and user passing
self.options = $.extend( {}, $.fn.sanbox.options, options );
console.log( this ); // an instance of Sanbox() object the caller
},
greet: function() {
console.log( 'work' );
}
};
// create your sanbox plugin
$.fn.sanbox = function(options) {
return this.each(function() {
var sanbox = Object.create(Sanbox);
sanbox.init(options, this);
})
}
// plugin default options
$.fn.sanbox.options = {
name : 'byer',
age : 24,
address : 'Lorem ipsum dolor sit amet.'
};
})(jQuery);
// use
我可以通过什么方式在 jQuery 插件定义之外使用/访问 greet() 方法?
在 init() 方法中,'this' 指的是什么?
【问题讨论】:
标签: javascript jquery