Lists - How do I set JavaScript variable as function and object same time?

19th of January 2014 0

How do I set JavaScript variable as function and object same time?

For example, jQuery use’s the “$ ” variable also as function and also as object.

$ (‘#id’) – selector function variable,
$ .ajax() – object variable,

How do I do this by myself?

Best answer:

Answer by Jeroonk
Quite easy:

function a(x) { … }; // can be called as just:
a( … );

a.b = function(x) { … }; // can be called as just:
a.b( … );

a.prototype.c = function(x) { … }; // must be called from an instance of a:
var instance = new a( … ); // In this case, ‘a( … )’ will serve as a constructor
instance.c( … );

Give your answer to this question below!

Filed under § jquery ajax — Tagged with , , , , , ,

Share it!

Was it good for you to?

Sponsors

Support for the site!

No sponsors at the moment.



Your opinion matters. Add it below.


Tip: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent comments

Categories



Copyright jqueryui.info since 2010. All rights reserved. Design and the Absolute Theme by Tommie Hansen.