We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,661 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Confusing about chaining

hi All,
I have question around Douglas Crockford "method" method.

Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};
function azerizor(value) {
this.value=value;
}


azerizor.method('toString', function () {

    return this.value;
});
var me = new azerizor('salam').toString();

alert(me);

this is it. But here arises question regarding return this?
what does mean here return this? this method works without return this. I have read about that. so that one say that it is for chaining. But i didnt understand how can i use chaining using this "method" function. Thanks in advance for attention. I will wait your responses!

2
Contributors
2
Replies
21 Hours
Discussion Span
4 Months Ago
Last Updated
3
Views
Question
Answered
azegurb
Posting Whiz in Training
260 posts since Sep 2009
Reputation Points: 11
Solved Threads: 2
Skill Endorsements: 0

Chaining is calling one function after another on the same object. Returning the object is a way to accomplish that. It allows you to write.

anObject.method1().method2().method3();
pritaeas
Posting Prodigy
Moderator
9,549 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,497
Skill Endorsements: 98

Thank you very much!

azegurb
Posting Whiz in Training
260 posts since Sep 2009
Reputation Points: 11
Solved Threads: 2
Skill Endorsements: 0
Question Answered as of 4 Months Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0682 seconds using 2.71MB