如何从内部重新加载jquery插件
How to reload jquery plugin from inside?
我需要从内部重新加载我的函数,我做了一个小片段:
function jqueryPlugin (selector, properties) {
this.properties = {
foo: properties.foo || 'foo',
bar: properties.bar || 'bar'
};
// this.element = $(selector);
// ...
console.log('element loaded... plugin start working...')
// ...
this.reload = function (properties) {
// ...
this(selector, properties); // ??
};
};
var instance = new jqueryPlugin('.foobar', {foo:'foooo'});
// ...
instance.reload({foo:'foobar'});
如您所见,它说this
不是一个函数。但是this
怎么能不是一个功能呢?我错过了什么?
这是因为this
是一个对象,而不是一个函数。尝试改用init
函数,如@RoryMcCrossan建议的那样:
function jqueryPlugin (selector, properties) {
this.init = function(selector, properties){
this.properties = {
foo: properties.foo || 'foo',
bar: properties.bar || 'bar'
};
//test if `this` is a function: console.log(this);
// this.element = $(selector);
// ...
console.log('element loaded... plugin start working...')
// ...
};
this.reload = function (properties) {
// ...
this.init(selector, properties); // ??
};
this.init(selector, properties);
};
var instance = new jqueryPlugin('.foobar', {foo:'foooo'});
// ...
instance.reload({foo:'foobar'});
相关文章:
- 使用javascript函数在页面初始化后加载jquery
- 什么'这是加载jQuery的最佳方式
- 在WordPress站点中加载jquery.js后加载javascript代码
- 延迟加载jquery后替换$(document).ready(function)
- 如何使用onLoad加载jQuery JSON.从Zipcode On Form获取城市和州
- 对页面重新加载 Jquery 执行操作
- 在Ajax(过滤器)加载之后加载jQuery脚本
- 异步加载JQuery时Tabbed Box已损坏
- 加载Jquery时Chrome扩展出错
- 在更改事件上加载jQuery DataTable
- 手动加载JQuery而不触发内容安全策略
- 如果更改,请在ng之后重新加载Jquery
- 脚本似乎在加载jQuery之前运行-未定义Uncaught ReferenceError:$
- 在使用jquery之前动态加载jquery
- 如何重新加载jquery,以便它能为下一个进程工作
- Firefox没有't从ajax.googleapis.com加载jquery
- 我无法在自定义Wordpress主题中成功加载jQuery
- 正在从maphilight href加载Jquery选项卡
- 如何在完全加载html之后加载jquery代码段
- 在页面加载jQuery/Javascript时,按.class对表行进行排序