jquery - How do I access other methods from within an event function? -


I am starting to learn more about jQuery plugin patterns, but I have participated in some of the code see below I want to access my plugins options / default with an onclick function, but I'm not sure how.

  Function SomePlugin (element, option) {This. $ El = $ (element); This.options = $ .extend ({}, {button: '# button', some variables: 'foo', another variable: 'bar'}, options); This.init (); } SomePlugin.prototype = {init: function () {var button = this. $ El.find (this.options.button) button ('Click', this.onClick); }, Onclick: function (event) {// options needed to access (some variables, another variable) here ... how? }}; $ .fn.someplugin = function (options) {return.Each (function () {if (! $. Data (this, 'some plugins')) {$. Data (this, 'some plugins', new plugins (this, option ));}}); };   

I have tried the code below, but it does not seem right for some reason. Is there a better way? Besides, I have any other suggestions or suggestions about my plugin structure, please tell me BTW I have left the jQuery cover for readability.

  function SomePlugin (element, option) { This.el = element; this. $ El = $ (element); This.options = $ .extend ({}, {button: '# button', some variables: 'foo', another variable: 'bar'}, options); This.init (); } SomePlugin.prototype = {init: function () {var button = this. $ El.find (this.options.button) button.on ('click', {instance: this}, this.onClick); }, Onclick: function (event) {// option event can be accessed by using data.instance.options ... Is there any easy way? }}; $ .fn.someplugin = function (options) {return.Each (function () {if (! $. Data (this, 'some plugins')) {$. Data (this, 'some plugins', new plugins (this, option ));}}); };    

When I wanted to write or understand the plugin, I used to use Jeffrey and It really works. Try below once viewed by the value link



Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -