astralaaron Posted July 5, 2015 Share Posted July 5, 2015 (edited) 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 July 5, 2015 by astralaaron Link to comment Share on other sites More sharing options...
Ingolme Posted July 5, 2015 Share Posted July 5, 2015 The function returns the same object that it is a method of. Link to comment Share on other sites More sharing options...
Ingolme Posted July 5, 2015 Share Posted July 5, 2015 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(); 1 Link to comment Share on other sites More sharing options...
astralaaron Posted July 9, 2015 Author Share Posted July 9, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now