Reputation: 7955
I know that sounds weird, but bear with me.
I have an object like this:
Functions = {
function1: function() {
function2: function() {
alert('bam');
}
}
}
How can I fire function2
? I tried Functions.function1.function2
and Functions.function1().function2()
but none works. Am I doing something wrong?
Upvotes: 0
Views: 81
Reputation: 13116
Here are two reworkings:
Keeping the function2 label
Functions = {
function1: function() {
function2:
(function() {
alert('bam');
})();
}
};
Functions.function1(); // You still can't access the label function2 however
Removing the function2 label (switch for a return
Functions = {
function1: function() {
return function() {
alert('bam');
};
}
};
Functions.function1()();
Bottom line is that the code doesn't work as it stand because you cannot treat a label as if it was a property of a function.
The closest you could get (as far as I can tell) to calling function2 off of function1 is (without a return statement):
Functions = {
function1: function() {
}
};
Functions.function1.function2 = function() {
alert("bam");
};
Functions.function1.function2();
Upvotes: 1
Reputation: 41
var test_func = {
test1:function(){
console.log("test1")
return {
test2:function(){
console.log("test2")
}
}
}
}
test_func.test1().test2()
Upvotes: 0