Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / June 2007



Tip: Looking for answers? Try searching our database.

OO question with anonymous functions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ed - 28 Jun 2007 18:40 GMT
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 - 28 Jun 2007 19:02 GMT
> I don't understand the point of using
> Widget.TagCloud.prototype = (function() return {   **object literal
[quoted text clipped - 3 lines]
> 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
-Lost - 30 Jun 2007 22:11 GMT
>> I don't understand the point of using
>> Widget.TagCloud.prototype = (function() return {   **object literal
[quoted text clipped - 6 lines]
> I think people just like showing off that they can make
> code that's difficult to understand. Maybe job security?

What is so difficult to understand about function expressions?

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions#The
_function_expression_.28function_operator.29


Also, see these 2 posts by RobG:

http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/81dc186
f8b18d43a/cae1a902ffd2b059?lnk=gst&q=author%3ARobG+function+expressions&rnum=1#c
ae1a902ffd2b059

http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/97fec2f
85a3e5213/9c747801812ebfc2?lnk=gst&q=author%3ARobG+function+expressions&rnum=2#9
c747801812ebfc2


Signature

-Lost
Remove the extra words to reply by e-mail.  Don't e-mail me.  I am
kidding.  No I am not.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.