OO question with anonymous functions

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
 
D

d d

ed said:
I don't understand the point of using
Widget.TagCloud.prototype = (function() return { **object literal
functions** })(this.data)
- 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.

I think people just like showing off that they can make
code that's difficult to understand. Maybe job security?

~dd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top