E
ed
Hi,
I was looking at the source of the following:
http://www.openjsan.org/doc/g/gu/gugod/Widget/TagCloud/0.02/lib/Widget/TagCloud.html
I don't understand the point of using
Widget.TagCloud.prototype = (function() return { **object literal
functions** })(this.data)
I (think...to some degree) I understand that:
- the return statement is returning a object literal
- the anonymous function is a closure used to make the "this"
statements in the literal object refer to the correct execution
context
What I don't understand is:
- why there are parenthesis around the code preceding the parameter
list *i.e. => (function() return... }) *, and what it does
- what advantages there are to using the anonymous function in the
first place... why not just set the prototype to the object literal
directly? I am guessing there are some encapsulation reasons, but I
am not sure what.
Any help?
-e
I was looking at the source of the following:
http://www.openjsan.org/doc/g/gu/gugod/Widget/TagCloud/0.02/lib/Widget/TagCloud.html
I don't understand the point of using
Widget.TagCloud.prototype = (function() return { **object literal
functions** })(this.data)
I (think...to some degree) I understand that:
- the return statement is returning a object literal
- the anonymous function is a closure used to make the "this"
statements in the literal object refer to the correct execution
context
What I don't understand is:
- why there are parenthesis around the code preceding the parameter
list *i.e. => (function() return... }) *, and what it does
- what advantages there are to using the anonymous function in the
first place... why not just set the prototype to the object literal
directly? I am guessing there are some encapsulation reasons, but I
am not sure what.
Any help?
-e