gpt4 book ai didi

javascript - `f()` 和 `new f()` 有什么区别?

转载 作者:数据小太阳 更新时间:2023-10-29 05:27:06 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is the 'new' keyword in JavaScript?
creating objects from JS closure: should i use the “new” keyword?

查看这段代码:

function friend(name) {
return { name: name };
}

var f1 = friend('aa');
var f2 = new friend('aa');

alert(f1.name); // -> 'aa'
alert(f2.name); // -> 'aa'

f1f2 有什么区别?

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