Note that there are some explanatory texts on larger screens.

plurals
  1. POConfused with declaring, using functions to be called from inside jquery plugin
    primarykey
    data
    text
    <p>I am writing my first jquery plugin. I have done the basic coding and would now like to refactor the code inside and put some sections inside functions. Please note that I do not want to call these functions from outside the plugin. Private functions, I think. This is somewhat the logic I want to put - </p> <pre><code>(function($) { $.fn.filterGroup = function(method) { var someParam,someOtherParam; //declared here and values updated inside someFunction(), anotherFunction() return this.each(function() { //plugin code starts here this.someFunction(); alert(someParam); //I want updated value of someParam to be available here $(inputTextField).keyup(function() {//as user enters input into an input field inputText = $(inputTextField).val(); //call a function here on this and does some modification on it. this.anotherFunction(); //move a lot of lines inside this function //on subsequent keyups, I want the updated value of someOtherParam to be available here alert(someOtherParam ); } }); //not sure where and how to declare these functions ... these needs to be called from inside the plugin only (private functions) someFunction = function(filterText) { //some logic on the passed this, not sure if my sentence is correct in terms of jquery... //var someParam is updated here someParam = "something"; } anotherFunction = function(filterText) { //var someOtherParam is updated here someOtherParam = "something"; } }); })(jQuery); </code></pre> <p>My question is - </p> <ul> <li>how and where do I define the <code>someFunction()</code> , so that I can call it like <code>this.someFunction();</code> . </li> <li>And, I need to be able to read the updated value of <code>someParam</code> during subsequent <code>onkeyup()</code> events. </li> </ul> <p>I checked the <em>Namespacing</em> section of <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow noreferrer">http://docs.jquery.com/Plugins/Authoring</a> but looks like that is about a public function to be called from outside. </p> <p>Also checked these questions - </p> <p><a href="https://stackoverflow.com/questions/1855383/jquery-using-functions-from-inside-a-plugin">Using functions from inside a plugin</a> and some others but I am confused.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload