Calling a function inside another on Class JS
I'm having trouble calling a specific function inside another on class. Example:
var class = {
function1 : {
function2 : {
class.function1.function3();
},
开发者_如何学JAVAfunction3 : {
// my code
}
}
}
Does anyone know how to simplify calling this function within function1?
You're declaring class, function1, 2 and 3 as objects, rather than functions. You need to do:
var class = {
function1 : {
function2 : function() {
class.function1.function3();
},
function3 : function() {
// my code
}
}
}
if you want to make function2
and function3
into actual functions. That said, you'll probably want to look into how OOP is done in JavaScript (which is what I'm guessing you're tryring to do), I'm sure google will give you some good hints. I'm no expert myself, but I guess you usually do it something like this:
function class() {
this.function2 = function() {
};
// etc.
}
var o = new class();
精彩评论