The same that you create (with any scripting language based in ECMAscript) one variable.

myvariable = "hello";  //now myvariable exists

You can declare any variable in one object (a property), by example in your jQuery object:

$.myvariable = "hello";
but it is possible that this can overwrite another method of a plugin that you use (if the method of one plugin is called "myvariable" and you have more possibilities if there are more variables. So,
normally is better to create one namespace inside the jQuery object:

$.mynamespace = {
   myvariable : "hello",
   myvariable1: "helloworld"
}

Or alternatelly,
$.mynamespace = {}
$.mynamespace.myvariable = "hello";
$.mynamespace.myvariable1= "helloworld";

Kia Niskavaara escribió:
How can I declare a new jQuery variable? I want it to be global, but I don't want to use the window object.

I know, a silly question. There shouldn't be any global variables, I know. But I need this for a temporary solution to a problem.

I would like to access it like this:

$.myvariable

or

$.myvariables.myvariable

Thank you for your help!!

Kia



--
Best Regards,
José Francisco Rives Lirola <sevir1ATgmail.com>

SeViR CW · Computer Design
http://www.sevir.org
Murcia - Spain

Reply via email to