473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

OO question with anonymous functions

ed
Hi,

I was looking at the source of the following:

http://www.openjsan.org/doc/g/gu/gug.../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

Jun 28 '07 #1
2 1261
d d
ed wrote:
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
Jun 28 '07 #2
d d wrote:
ed wrote:
>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?
What is so difficult to understand about function expressions?

http://developer.mozilla.org/en/docs...on_operator.29

Also, see these 2 posts by RobG:

http://groups.google.com/group/comp....e1a902ffd2b059
http://groups.google.com/group/comp....747801812ebfc2

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
6
by: TS | last post by:
Does anyone know if the Mac Browsers (IE5 / Safari) support anonymous functions or lambda functions? Ive been trying to get a site working with the Mac browsers and just cant get it to work. Here...
10
by: Joshua Nussbaum | last post by:
I came up with what I think is a good idea for making multithreading programming easier in any .NET language. I dont know where else to post it, so I'll try here. ..NET 2.0 adds the capability...
8
by: SAN CAZIANO | last post by:
i have to do in the onkeypress or in onchange the float (real) field validation I try something: function ValidaCampo(nomeCampo,TotInteri,TotDecimali) {...
8
by: Robert A Riedel | last post by:
I have an application that requires a DLL and an executable that uses the DLL, both of which were implemented in Visual C++ using unmanged code. Both the executable and the DLL are linked with...
60
by: jacob navia | last post by:
Gnu C features some interesting extensions, among others compound statements that return a value. For instance: ({ int y = foo(); int z; if (y>0) z = y; else z=-y; z; }) A block enclosed by...
3
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
7
by: Gregor Kofler | last post by:
What is the best practice for removing anonymous functions? Something like (function() { doSomething(); arguments.callee = null; })(); seems to work (at least it triggers no errors or...
22
by: Luna Moon | last post by:
I am reading the book "C++ Annotations", and here is a quote from the book: Namespaces can be defined without a name. Such a namespace is anonymous and it restricts the visibility of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.