krycek
11-04-2002, 12:41 AM
OK, here are two related questions concerning functions:
----- 1. -----
If I have a function called f1(), I can nest another function within this by saying:
function f1() {
this.greeting = "hello"
}
function f2() {
this.greeting = "hi"
}
f1.f2 = new f2()
--- OR ---
function f1() {
this.greeting = "hello"
this.f2 = function {
this.greeting = "hi"
}
}
Now, in the first example, I can say f1.greeting or f1.f2.greeting. Also, I can add multiple layers of functions, e.g. f1.f2.f3.f4.greeting.
In the second example, I have the following two questions:
A: How do I add multiple nests of functions?
B: How should I reference them, both inside and outside the functions? e.g. are variables always this.greeting which would then be f1.f2.f3.greeting etc. - or would it be this.f1.f2.f3.greeting = , etc.
The reason I need to know this is that I have a working nest using the first method, and prototypes, but I would like it all contained within the first function if possible, because the nested functions should not be available outside of the parent.
----- 2. -----
My second question is purely about prototyping:
If I want to add a function to an object, I can say:
myObject.prototype.myFunction = function() {} etc.
I can use my own objects for this, or else extend predefined JavaScript objects, for example:
Array.prototype.myFunction...... etc.
Now, I would like to be able to add some functions to textboxes if possible, but I do not see any way to do this. I assume it is not possible, but apparently it is possibly to add to an Image object...?
So, my question is:
A: What kinds of objects exist, and which can be extended?
B: Do they have any relation to the HTML equivalent? i.e. is Image equivalent to <img> ?
C: Is it possible for me to add a function to every single <input> box, or not?
:confused:
Thanks people for the help, I know someone out there has the answers! :)
::] krycek [::
----- 1. -----
If I have a function called f1(), I can nest another function within this by saying:
function f1() {
this.greeting = "hello"
}
function f2() {
this.greeting = "hi"
}
f1.f2 = new f2()
--- OR ---
function f1() {
this.greeting = "hello"
this.f2 = function {
this.greeting = "hi"
}
}
Now, in the first example, I can say f1.greeting or f1.f2.greeting. Also, I can add multiple layers of functions, e.g. f1.f2.f3.f4.greeting.
In the second example, I have the following two questions:
A: How do I add multiple nests of functions?
B: How should I reference them, both inside and outside the functions? e.g. are variables always this.greeting which would then be f1.f2.f3.greeting etc. - or would it be this.f1.f2.f3.greeting = , etc.
The reason I need to know this is that I have a working nest using the first method, and prototypes, but I would like it all contained within the first function if possible, because the nested functions should not be available outside of the parent.
----- 2. -----
My second question is purely about prototyping:
If I want to add a function to an object, I can say:
myObject.prototype.myFunction = function() {} etc.
I can use my own objects for this, or else extend predefined JavaScript objects, for example:
Array.prototype.myFunction...... etc.
Now, I would like to be able to add some functions to textboxes if possible, but I do not see any way to do this. I assume it is not possible, but apparently it is possibly to add to an Image object...?
So, my question is:
A: What kinds of objects exist, and which can be extended?
B: Do they have any relation to the HTML equivalent? i.e. is Image equivalent to <img> ?
C: Is it possible for me to add a function to every single <input> box, or not?
:confused:
Thanks people for the help, I know someone out there has the answers! :)
::] krycek [::