0
javascript?中defaults: function($super)
和domain: function($super)
的含義是什麼?以下代碼取自openstack-horizon。他們正在使用非常高水平的JavaScript概念,但我知道基本的JavaScript。javascript中的域和默認函數的含義是什麼?
Rickshaw.Graph.Renderer.StaticAxes = Rickshaw.Class.create(Rickshaw.Graph.Renderer.Line, {
name: 'StaticAxes',
defaults: function($super) {
alert("13 => This is repeated many time. Rickshaw.Graph.Renderer.StaticAxes");
return Rickshaw.extend($super(), {
xMin: undefined,
xMax: undefined,
yMin: undefined,
yMax: undefined
});
},
domain: function($super) {
//alert("HJ");
var ret = $super();
var xMin, xMax;
// If y axis wants to have static range, not based on data
if (this.yMin !== undefined && this.yMax !== undefined) {
ret.y = [this.yMin, this.yMax];
}
// If x axis wants to have static range, not based on data
if (this.xMin !== undefined && this.xMax !== undefined) {
xMin = d3.time.format.utc('%Y-%m-%dT%H:%M:%S').parse(this.xMin);
xMin = xMin.getTime()/1000;
xMax = d3.time.format.utc('%Y-%m-%dT%H:%M:%S').parse(this.xMax);
xMax = xMax.getTime()/1000;
ret.x = [xMin, xMax];
}
return ret;
}
});
這兩個語句都將函數分配給對象文字鍵。當你調用'defaults'時,它會調用分配的函數。當你調用'domain'時,它會調用其他函數。有關更多信息,請參閱**對象文字** – jasonscript