Javascript 将变量传递给嵌套箭头函数

Javascript 将变量传递给嵌套箭头函数,javascript,node.js,ecmascript-6,arrow-functions,Javascript,Node.js,Ecmascript 6,Arrow Functions,我有一个包含嵌套箭头函数的函数。嵌套箭头函数需要访问变量属性,该属性总是未定义。为什么呢?如何使e.getAttribute()accessattribute变量 this.getAttr = async (locator, attribute) => { return await page.$eval(locator, e => e.getAttribute(attribute) ); }; 只要为它的第二个参数传递

我有一个包含嵌套箭头函数的函数。嵌套箭头函数需要访问变量
属性
,该属性总是
未定义
。为什么呢?如何使
e.getAttribute()
access
attribute
变量

this.getAttr = async (locator, attribute) => {
        return await page.$eval(locator, e =>
                e.getAttribute(attribute)
        );
};

只要为它的第二个参数传递了一个值,
.getAttr()
,它就会工作得很好。您是否在
return
语句之前尝试了
console.log(attribute)
,以验证它是否已定义?
页面。$eval
表明您正在使用某种web测试框架。这些将实际序列化您的函数并在页面上重新创建它。序列化过程会丢失所有的闭包引用。谢谢你们给我指明了正确的方向。下面是工作代码
this.getAttr=async(locator,attribute)=>{return wait page.$eval(locator,(element,attribute)=>{return element.getAttribute(attribute);},attribute);}