调用在JavaScript中另一个函数内部的函数 [英] call to a function that inside another function in JavaScript

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

问题描述

我想调用另一个功能中的一个功能.

函数示例:

  function funcOne(){函数funcTwo(){//我想调用此函数//做一点事}} 

当我单击这两个函数的外部之外的按钮时,我需要调用 funcTwo 函数

我该怎么办?

解决方案

否,除非您返回该函数,否则无法调用.

Function2是function1专用的.

您使用

  function funcOne(){返回 {funcTwo:function(){//我想调用此函数//做一点事}}} 

编辑:构建代码

  function funcOne(){var funcTwo = function(){//私有函数//做一点事}返回 {funcTwo:funcTwo}} 

现在您可以将其称为:

  funcOne().funcTwo() 

I want to call a function that is in another function.

example for the functions:

function funcOne() {
     function funcTwo() {    // i want to call to this function
         //do something
     }
}

I need to call to funcTwo function, when I click on a button which is outside of these two functions

how can i do it?

解决方案

No, You can't call unless you return that function.

Function2 is private to function1.

you use

function funcOne() {
    return {
     funcTwo :function() {    // i want to call to this function
         //do something
     }
   }
}

EDIT: Structuring code

function funcOne() {
   var funcTwo = function() {    // private function
        //do something
     }
    return {
      funcTwo : funcTwo      
   }
}

Now you can call it as:

funcOne().funcTwo()

这篇关于调用在JavaScript中另一个函数内部的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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