87,904
社区成员
发帖
与我相关
我的任务
分享
// 发送类型 get、post
var type = "get"
var config = {
type: type
}
function ajax() {
console.log(config)
}
// 数据类型 json、html
var type = "json"
var config = {
type: type
}
function data() {
console.log(config)
}
//当你使用全局变量时候, 这个时候出现了变量冲突
// 闭包避免type, config等等变量的冲突, 最终我们只需要暴露ajax和data在window就可以了
(function(w) {
var type = "get"
var config = {
type: type
}
function ajax() {
console.log(config)
}
w.ajax = ajax
})(window);
(function(w) {
var type = "json"
var config = {
type: type
}
function data() {
console.log(config)
}
w.data = data
})(window);