全局命名空间变量?
我正在尝试做类似的事情
(function( skillet, $, undefined ) {
skillet.global = {
names: {
first: 'abe',
last: 'watson'
},
addresses: {
home: 'blah'
}
}
}( window.skillet = window.skillet || {}, jQuery ));
以便我可以访问
skillet.global.names.first();
skillet.global.address.home();
但我不断收到错误?我该如何解决这个问题
I am trying to do something like
(function( skillet, $, undefined ) {
skillet.global = {
names: {
first: 'abe',
last: 'watson'
},
addresses: {
home: 'blah'
}
}
}( window.skillet = window.skillet || {}, jQuery ));
So that I can access like
skillet.global.names.first();
skillet.global.address.home();
But I keep getting errors ? How can I go about fixing this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在调用
first
和home
,就好像它们是函数一样;但您已将它们定义为对象属性。调用
skillet.global.names.first
(如果在警报中)将显示abe
,如果您需要在函数中定义它们,则需要使用正确的函数声明, IEYou are calling
first
andhome
as if they were functions; yet you have defined them as object properties.Calling
skillet.global.names.first
would (if in an alert) showabe
, if you need to define them in functions, you need to use the correct function declaration, i.e.将
skillet.global.names.first();
更改为skillet.global.names.first;
更改
skillet.global.address.home();
代码>到skillet.global.addresses.home;
change
skillet.global.names.first();
toskillet.global.names.first;
change
skillet.global.address.home();
toskillet.global.addresses.home;