如果两个.js
文件有相同名称和参数的函数,但代码不同。使用 bundle.config
bundle 后会发生什么?
哪个会打电话?
或者/我们如何解决这个问题?
//in parent.js file
function getdetails(id)
{
//enter code here
}
//in student.js file
function getdetails(id)
{
//enter code here
}
最佳答案
根据打包器的类型,通常函数的作用域是它们从中导出的模块。
例如:
//in parent.js file
function getdetails(id)
{
//enter code here
}
//in student.js file
function getdetails(id)
{
//enter code here
}
在 bundle 的 javascript 中,它们变成(作为一般示例):
_parent.getdetails()
_student.getdetails()
您可以检查未缩小的 bundle 代码并搜索 getdetails
以查看函数的作用范围以进行说明。
边注
如果两个函数在相同的范围内以相同的名称定义(这里不应该是这种情况),那么每次都重新定义该函数。
//in parent.js file
function getdetails() {console.log("foo");}
function getdetails() {console.log("bar");}
getdetails(); // Outputs "bar"
关于javascript - 使用 bundle.config bundle 2 个具有相同名称和参数的函数的 .js 文件后会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56233308/