Jump to content

Javascript structure


astralaaron

Recommended Posts

I was wondering how to write a structure like jquery does for example so that you can select an element like: somescript('some_element').someMethod();

 

etc...how do you chain together basically??? thank you

 

the first function would just return the element..then whatever function you did after would run on that element

Edited by astralaaron
Link to comment
Share on other sites

To be more clear. The first function $() returns an object, and methods of that object return the exact same object.

 

Here's a simplified example:

function a(x) {  return {    value : x,    b : function() { return this; }    c : function() { return this; }  }}a("A").b().b();
  • Like 1
Link to comment
Share on other sites

Ignolme I really appreciate you responding. I'm sorry for such a late response, when I returned home from work, my computer monitor wouldn't turn on. Your example makes sense, I will play around with it soon and let you know how it went!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...