{ var -6ren">
gpt4 book ai didi

javascript - 将 $(this) 编译为 $(_this)

转载 作者:搜寻专家 更新时间:2023-10-30 22:04:52 25 4
gpt4 key购买 nike

我在使用 TypeScript 将 $(this) 替换为 $(_this) 并破坏代码时遇到问题,因为 test 指的是 窗口

$(".class").click(() => {
var test = $(this);
console.log(test);
});

编译为

$(".class").click(function () {
var test = $(_this);
console.log(test);
});

最佳答案

如果您不想捕获词法 this,请不要使用箭头函数。只需使用正则函数表达式:

$(".class").click(function () {
var test = $(this);
console.log(test);
});

关于javascript - 将 $(this) 编译为 $(_this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37147394/

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