Decided to rebuild an jQuery plugin in vanilla JS I run into an issue, I cant seem to get the plublic methods to work. All other logic works but not the public mehtods. I have include the update method as an example.
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory(root));
} else if (typeof exports === 'object') {
module.exports = factory(root);
} else {
root.Plug = factory(root);
}
})(typeof global !== "undefined" ? global : this.window || this.global, function(root) {
var _settings;
var defaults = {
// default values
}
function runPlugin(){
alert('it works')
}
var Plug = function(options) {
var Plug = {};
var settings;
_settings = extend(settings || defSettings, options || {});
var init = (function() {
//init logic
runPlugin();
...
}());
Plug.update = function(msg){
alert(msg)
}
}
return Plug;
});
var plug = new Plug({//settings...}); //works
var plug = new Plug().update('test'); //does not work
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…