I’m learning to use object literals in JS, and I’m trying to get a function inside an object to run by calling it through another function in the same object. Why isn’t the function “run” running when calling it from the function “init”?
JavaScript
x
11
11
1
var RunApp = {
2
3
init: function(){
4
this.run()
5
},
6
7
run: function() {
8
alert("It's running!");
9
}
10
};
11
Advertisement
Answer
That code is only a declaration. You need to actually call the function:
JavaScript
1
2
1
RunApp.init();
2