简体   繁体   English

函数内部的JavaScript调用函数

[英]Javascript calling function inside function

I am trying to get the function in a function with argument inside the child function 我正在尝试在子函数内部带有参数的函数中获取该函数

function firstF (){
  this.childF1 = function($argument){
    // do something + $argument
  }
  this.childF2 = function($argument2){
    // do something + $argument2
  }
}

//Declare a new firstF
var firstFunction = new firstF();
firstFunction.childF1

how do i declare the $argument here? 我如何在这里声明$参数?

You do it like this: 您可以这样做:

var firstFunction = new firstF();
firstFunction.childF1(arghere)

childF1 is a property of your firstF object and that property is a function. childF1firstF对象的属性,而该属性是一个函数。 So, you call it like a function with parens and you pass the arguments in the parens. 因此,您可以将其称为带有parens的函数,然后在parens中传递参数。 You must call it on an already created object of type firstF , not on the firstF function itself. 您必须在一个已经创建的类型为firstF对象上调用它,而不是在firstF函数本身上调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM