views:

28

answers:

1

Hey again all :)

I created my own jQuery plugin in 1.4 and now I need a small amount of help.

$.etrade = function()
{

}

I need so I can build code like this

$.etrade = function()
{
    this.var = 'setting';

    this.subfunction = function()
    {
    };
}

when I take function from my plugin I need to use it like this:

$.etrade.var = '5';
$.etrade.subfunction();

Somebody know what I mean? and how I can get this problem done? :)

+3  A: 

It sounds like you want to assign a plain old object to $.etrade, not a function. Like this:

$.etrade = {
    variable: 'setting',
    otherVariable: 'something else',
    subfunction: function () { /* do stuff here */ },
    anotherSubFunction: function () { /* do other stuff here */ }
}

That said, I'm not sure how this qualifies as a jQuery plugin, since it looks like you're just tacking an ad-hoc property onto jQuery.

Aside: you can't use var as per your example, since it's a keyword in JavaScript.

Matt Ball
i know var its a keyword, its only a example, :) so, if i need more subfunction so i only need newfunction: function(){} ?
NeoNmaN
@NeoN: okay, just making sure. Re: more subfunctions- yes, that's exactly right.
Matt Ball
will you plase make a sample :0) so im 100% understand. :)
NeoNmaN
@NeoN: sure, check my edit. Is that what you were looking for?
Matt Ball