Accessing a function object's properties from within the functionbody

R

reycri

Hi,

Given the following code:

var func = new function("prm1", "prm2",
"... <access this function object's properties (prop1 and
prop2) here inside the body>...");
func.prop1 = 123;
func.prop2 = "abc";
...... <pass func as an async callback param to another object (eg:
prototype's Ajax.Request)>.....

Within the body of "func", what is the syntax to access this function
object's "prop1" and "prop2" properties?

Thanks in advance,

Rey
 
H

Henry

Given the following code:

var func = new function("prm1", "prm2",
"... <access this function object's properties
(prop1 and prop2) here inside the body>...");

The use of the - new - operator would indicate that the value assigned
to your - func - variable is an ordinary object not a function. There
may be code inside your 'constructor' that changes that, but you have
not shown it and if it is there it is more relevant to this question
than anything else shown.
func.prop1 = 123;
func.prop2 = "abc";
..... <pass func as an async callback param to another
object (eg: prototype's Ajax.Request)>.....

So you have got to the point of having to jump through hoops to
mitigate for the design flaws in Protoype.js?
Within the body of "func", what is the syntax to access
this function object's "prop1" and "prop2" properties?

Within the body of _a_ function object (that had - prop1 - and - prop2
- properties):-

arguments.callee.prop1
arguments.callee.prop2

- but it looks like not having the type of object you think you have
is going to be a bigger barrier to getting this to work.
 
R

reycri

The use of the - new - operator would indicate that the value assigned
to your - func - variable is an ordinary object not a function. There
may be code inside your 'constructor' that changes that, but you have
not shown it and if it is there it is more relevant to this question
than anything else shown.


So you have got to the point of having to jump through hoops to
mitigate for the design flaws in Protoype.js?


Within the body of _a_ function object (that had - prop1 - and - prop2
- properties):-

arguments.callee.prop1
arguments.callee.prop2

- but it looks like not having the type of object you think you have
is going to be a bigger barrier to getting this to work.

Sorry, I mistyped my original post. The first line of the code snippet
should have been:

var func = new Function("prm1", "prm2", "... <access this function
object's properties (prop1 and
prop2) here inside the body>...");

The correction being the capital "F" for the constructor call. In this
case, I was creating an instance of the Javascript standard function
object.

Thanks for your reply, though. I completely forgot about the "callee"
property on a function objects "arguments" property.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top