简体   繁体   English

在另一个函数JavaScript中访问函数参数

[英]Access function parameter in another function JavaScript

How to access function's parameter in another function that invoke it, here's what I mean 如何在调用该函数的另一个函数中访问函数的参数,这就是我的意思

function one(a){
  b();
}

function b(){
  //'a' is the parameter of function one
  if(a>0){
   //do some stuff
  }
}

//the parameter 'a' of function one goes here to catch an event
element.addEventListener('wheel', one);

Can I access function one parameter in function b? 我可以访问函数b中的一个参数吗?

Pass the parameter into b as well 也将参数传递给b

function one(a){
  b(a);
}

function b(a){
  //'a' is the parameter of function one
  if(a>0){
   //do some stuff
  }
}

You have to pass a to function b as follows. 您必须将a传递给功能b ,如下所示。

function one(a){
  b(a);
}

function b(a){
  //'a' is the parameter of function one
  if(a>0){
   //do some stuff
  }
}

//the parameter 'a' of function one goes here to catch an event
element.addEventListener('wheel', one);

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

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