gpt4 book ai didi

函数内部的Javascript调用函数

转载 作者:行者123 更新时间:2023-11-30 18:06:12 26 4
gpt4 key购买 nike

我正在尝试在子函数中获取带有参数的函数

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

如何在这里声明 $argument?

最佳答案

你这样做:

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

childF1 是您的 firstF 对象的一个​​属性,该属性是一个函数。因此,您可以像调用带括号的函数一样调用它,并在括号中传递参数。您必须在类型为 firstF 的已创建对象上调用它,而不是在 firstF 函数本身上调用它。

关于函数内部的Javascript调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15755249/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com