gpt4 book ai didi

javascript - 显示模块模式时的额外括号

转载 作者:搜寻专家 更新时间:2023-10-30 21:07:27 26 4
gpt4 key购买 nike

<分区>

我正在查看由 TypeScript 编译器生成的一些代码,我注意到它在额外的括号中包装了来自揭示对象模式的函数。我认为这是有原因的,原因是什么?

var Castle = (function () {
function Castle(name) {
this.name = name;
}
Castle.prototype.Build = function () {
var element = document.getElementById("textArea");
console.log("Built " + this.name);
};
return Castle;
})();
var test = new Castle("Winterfell");
test.Build();

注意外部函数在 () 中。没有它们,代码似乎也能正常工作。

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