从对象内的函数调用函数(对象文本) [英] Call functions from function inside an object (object literal)

查看:66
本文介绍了从对象内的函数调用函数(对象文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习在JS中使用对象文字,我试图通过在同一对象中调用另一个函数来获取对象中的函数。为什么从函数init调用函数时不运行run?

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"?

var runApp = {

    init: function(){   
         this.run()
    },

    run: function() { 
             alert("It's running!");
    }
};


推荐答案

STRONG>。您需要实际调用函数:

That code is only a declaration. You need to actually call the function:

runApp.init();

演示: http://jsfiddle.net/mattball/s6MJ5/

这篇关于从对象内的函数调用函数(对象文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆