我的编码问题请查看以下代码
var sliderFunction = {
init: function(sliderSettings) {
sliderFunction.sliderSettings();
},
sliderSettings: function() {
var sliderDiv = $('.slider');
var ulDiv = $('.slider ul');
var liDiv = $('.slider ul li');
var sliderWidth = sliderDiv.width();
var countLi = liDiv.length;
var ulTotalWidth = sliderWidth * countLi;
ulDiv.outerWidth(ulTotalWidth);
},
nextContent: function() {
}
}
sliderFunction.init();
我想在nextContent函数中使用sliderSettings函数的var访问权限。我怎么能这样做
提前致谢
答案 0 :(得分:1)
在全局范围内定义它们,它们可以随意访问
var sliderDiv,ulDiv,liDiv,sliderWidth,countLi,ulTotalWidth,ulDiv;
var sliderFunction = {
init: function(sliderSettings) {
sliderFunction.sliderSettings();
},
sliderSettings: function() {
sliderDiv = $('.slider');
ulDiv = $('.slider ul');
liDiv = $('.slider ul li');
sliderWidth = sliderDiv.width();
countLi = liDiv.length;
ulTotalWidth = sliderWidth * countLi;
ulDiv.outerWidth(ulTotalWidth);
},
nextContent:function(){
console.log(sliderDiv,ulDiv,liDiv,sliderWidth,countLi,ulTotalWidth,ulDiv);
}
}