我在从另一个 JS 文件创建有用事物的实例时遇到了一些麻烦,我想更改实例的属性并使用这些方法。或者如果这是不可能的,你建议什么。这扩展了,这个结构让我感到困惑。
(function($) {
$.extend({
usefulThings: new function() {
this.defaults = {
prop_path:'/la/lala',
//OTHER STUFF
};
this.construct = function(options) {
return this.each(function() {
var setting;
this.settings = {};
settings = $.extend(this.settings, $.usefulThings.defaults, options);
$this = $(this);
//OTHER STUFF
$.data(this, "usefulThings",settings);
// FIRST METHOD CALL
//OTHER STUFF
});
};
//SOME METHODS
}
});
$.fn.extend({
usefulThings: $.usefulThings.construct
});
})(jQuery);
我见过从脚本块调用的有用事物,如下所示:
$("#myDivName").usefulThings({
prop_path: '/la/lala' //these seems to get overwritten in the above
});