javascript - JQuery plugin scope problems -
I feel a little ignorant, but I think some education will not hurt me.
I have simplified my code to outline the problem - the problem is that when Fu () is said from within the init method, it is believed that the Worldwide, A, B Can not use C and settings. These laws are defined outside the field, so why are they not reachable?
For example, the settings are clearly defined before the foo call, so why not see the foo setting?
(function (jquery) {a = new date (); var b; var c = 1; settings = 0; // here or not - same issue var methods = {init: function (Settings) {c = $ (this); settings = jQuery.extend ({id: Math forrest (Math.Random) * 1001), X: 3; etc: 2}, Settings || {}); M = 1; af ();}}; function fu () {x = settings.x; / / settings var n = cm; return x;} jQuery.fn.bar = function (method) {if (methods [method]) // If we have a method that is {return methods [method]. Aply (this, Array.prototype.slice.call (argument, 1));} and if (method of type === 'object' || ! Method) // Otherwise if we have an object (settings) Or nothing, then init. {Return methods.init.apply (; this, argument);} and ($ .error ('method' + method + 'does not exist'); // otherwise we have There is an error.}};}); Any thoughts?
You are creating a local copy settings when you define it as the argument of your init function:
// Here is a global setting init: function ( Settings) {// here is a local setting // changes have been made So when Foo is called setting 0 is still, and you are reaching number (0) .x which is Is undefined. Simply deleting the local copy of the settings will solve your problem:
init: function (s) { and replace Settings || {} to s || {}
Comments
Post a Comment