473,408 Members | 1,854 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,408 software developers and data experts.

Add properties to function while in function with out specifying function ?

I can add a property to a function while in the function

function foo () {
foo.X=1;
}
alert (foo.X) // undef
foo()
alert (foo.X) //1

or

function foo (name,value) {
foo [name] = value
}
foo ('A',1)
alert (foo.A) // 1

how would I add a property to currently running function without naming the
function ?

self doesn't work
function foo (name,value) {
self [name] = value
}
foo ('A',1)
alert (foo.A)
alert (self['A'])

function foo ( name, value ) {
**something** [name] = value
}
foo ('X',9)
alert (foo.X) // want 9

What would **something** be ?

--
Richard A. DeVenezia

Jul 20 '05 #1
4 1634

"Richard A. DeVenezia" <ra******@ix.netcom.com> schreef in bericht
news:bj************@ID-168040.news.uni-berlin.de...

function foo ( name, value ) {
**something** [name] = value
}
foo ('X',9)
alert (foo.X) // want 9

What would **something** be ?


function foo ( name, value ) {
foo[name] = value
}
JW

Jul 20 '05 #2
"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> wrote in message
news:3f***********************@news.euronet.nl...

"Richard A. DeVenezia" <ra******@ix.netcom.com> schreef in bericht
news:bj************@ID-168040.news.uni-berlin.de...

function foo ( name, value ) {
**something** [name] = value
}
foo ('X',9)
alert (foo.X) // want 9

What would **something** be ?
function foo ( name, value ) {
foo[name] = value
}
JW

I found what I was looking for.

function foo (name,value) {
var callee = arguments.callee
callee[name] = value
}
foo ('X', 9)
alert (foo.X)

presumed to be the same as
function foo ( name, value ) {
foo[name] = value
}


but not needing to know the function name at source writing time.

--
Richard A. DeVenezia
Jul 20 '05 #3
> I can add a property to a function while in the function

function foo() {
foo.X = 1;
}


Ideally yes, but IE has a bug which frustrates that pattern, requiring instead

foo = function () {
foo.X = 1;
};

http://www.crockford.com/javascript/remedial.html

Jul 20 '05 #4
"Douglas Crockford" <no****@laserlink.net> writes:
Ideally yes, but IE has a bug which frustrates that pattern,
requiring instead


Which version of IE is that, and what is the bug?
It would sound like it prevents function declarations from declaring
recursive functions.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

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

Similar topics

21
by: Peter Bassett | last post by:
I have a .shtml file, that displays photos, in which I wish to pass some functionality off to an Include file for reusability purposes. Unfortunately, it's not working. Here is a portion of the...
4
by: yawnmoth | last post by:
I'm trying to write a script to make images fade in and out using the varrious CSS attitrubes that browsers use for that purpose. In an a tag, surrounded an image, I pass to the fade function the...
0
by: aj | last post by:
DB2 v8 FP5 Red Hat AS/EL 2.1 I am specifying properties for a DB2 Universal JDBC Driver connection in my Java/JDBC app by creating a java.util.Properties object and passing it along in my...
2
by: Glenn Shukster | last post by:
Hi In Delphi a call to SetSubComponent will expose all of a subcomponents properties and events at design time to the main component. Does anyone know how to do this in CSharp? eg MyObject +...
4
by: Darrell Sparti, MCSD | last post by:
There have been many postings about this subject on this newsgroup. Unfortunately, they're incorrect. You can't just cast a value in C# and have it work for all ASCII characters. Nor can you use...
2
by: Nathan Sokalski | last post by:
I am sure most of us have enough experience with HTML to know that most HTML elements allow you to specify the width and/or height attributes as percentages. However, I have noticed that when...
4
by: Suresh | last post by:
Is there any way to access the custom properties of a master page from the aspx form? I know the custom properties of a master page can be accessed from the aspx.cs partial class by specifying...
4
by: beatdream | last post by:
I am designing a database to handle different kinds of products ... and these products can have different properties...for example, a trouser can be specified by the width, length, color, and other...
0
debasisdas
by: debasisdas | last post by:
WINDOWING FUNCTION:- ==================== ORACLE'S WINDOWING FUNCTIONS ALLOW AGGERGATES TO BE CALCULATED FOR EACH ROW IN A RESULT SET BASED ON A SPECIFIED WINDOW.THE AGGREGATION WINDOW CAN BE...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.