gpt4 book ai didi

javascript - 如果使用对象样式向函数添加属性会发生什么情况?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:42:28 27 4
gpt4 key购买 nike

奇怪的是,以下代码在最新的 Chrome 浏览器中没有报错:

function func(){
x:1
}
func();

到底发生了什么?(我不是要向函数添加属性,我知道如何使用 func.propertyarguments.callee.property 来做到这一点)

更新:如果x:1是一个labeled statement,那么

function func(){
1
}

被认为是一个有效的函数。 1 在这里做什么?它只是被忽略了吗?是语句、表达式还是其他?

最佳答案

你的线路

x:1

是一个labeled statement .

The labeled statement can be used with break or continue statements. It is prefixing a statement with an identifier which you can refer to.

Example :

var i = 0;
var j = 8;

checkiandj: while (i < 4) {
console.log("i: " + i);
i += 1;

checkj: while (j > 4) {
console.log("j: " + j);
j -= 1;

if ((j % 2) == 0)
continue checkj;
console.log(j + " is odd.");
}
console.log("i = " + i);
console.log("j = " + j);
}

关于javascript - 如果使用对象样式向函数添加属性会发生什么情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37407970/

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