我正在处理一个 JavaScript 对象,其中声明了很多变量。我想要做的是引用父对象的另一个子对象。给定以下对象:
var clusters = {
auxiliars: {
environment : "Development",
local_storage_key : "Cluster",
iqns_class : ".iqn",
iqn : this.iqns_class.parent(),
viewport : $(window),
viewport_width : this.viewport.width(),
viewport_height : this.viewport.height(),
plugin : {
containerID : "",
first : false,
previous : false,
next : false,
last : false,
startPage : 1,
perPage : 6,
midRange : 6,
startRange : 1,
endRange : 1,
keyBrowse : false,
scrollBrowse: false,
pause : 0,
clickStop : true,
delay : 50,
direction : "auto",
animation : "fadeIn",
links : "title",
fallback : 1000,
minHeight : true,
callback : function(pages, items) {}
}
},
set_local_storage_data: function(data_val) {
return localStorage.setItem(auxiliars.local_storage_key, data_val);
},
get_local_storage_data: function() {
return +(localStorage.getItem(auxiliars.local_storage_key) || 1);
},
set_environment: function(environment) {
if(auxiliars.environment == "Development") {
less.env = "development";
less.watch();
}
},
shop_iqns_selected_class: function() {
if (auxiliars.viewport_width < 980) {
$(auxiliars.iqns_class).each(function(index, element) {
var element = $(element);
$(auxiliars.iqn).on('click', function() {
if (element.hasClass('selected')) {
element.removeClass('selected');
} else {
element.addClass('selected');
}
});
});
}
},
initiate_plugin: function(plugin_navigation, plugin_options) {
var options = $.extend({}, auxiliars.plugin, plugin_options);
return $(plugin_navigation).jPages(options);
}
}
你会注意到this.viewport.width()
,我想指向viewport
在同一个auxiliars
对象中声明的变量。显然我得到了一个错误,但是我怎么能指向同一个对象的那个子值呢?