拥有一个具有功能的对象,更好的方法是什么?使用对象的变量或属性?
function Panels(){
var self = this;
//properties <-------------
self.position = 'top';
self.color = 'black';
self.numPanels = 0;
self.addPanel = function(){
self.numPanels++;
};
self.getNumPanels = function(){
return self.numPanels;
}
}
VS
function Panels(){
var self = this;
//variables <-------------
var position = 'top';
var color = 'black';
var numPanels = 0;
self.addPanel = function(){
numPanels++;
};
self.getNumPanels = function(){
return numPanels;
}
}
只是将它们公之于众,并且可以从外部访问吗?或者关于覆盖全局变量?