在不同的.js文件中使用两个同名的方法 [英] Use two methods of the same name in different .js files
本文介绍了在不同的.js文件中使用两个同名的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个同名的方法,用于两个不同的.js文件中的不同目的。如何在同一页面上使用这些方法?
I have two methods with the same name, for different purposes in 2 different .js files. How can I use those methods on same page?
在Count.js中:
In Count.js:
function add()
{
// some manipulation doing here
}
在PriceImplement中。 js
In PriceImplement.js
Function add()
{
// some manipulation doing here
}
推荐答案
你应养成命名空间的JavaScript文件的习惯:
You should get into the habit of namespacing your JavaScript-files:
// Count.js:
//Count.js:
var Count = {
add: function add() {
},
[additional methods in the Count object]
};
// PriceImpl.js
// PriceImpl.js
var Price = {
add: function add () {
},
[additional methods for the Price implementation]
};
然后调用 Namespace.method
等方法,即 Price.add()
这篇关于在不同的.js文件中使用两个同名的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文