javascript中defaults: function($super)
和domain: function($super)
的含义是什么?以下代码取自openstack-horizon。他们使用非常高水平的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;
}
});
答案 0 :(得分:1)
考虑这段代码。
var objectLiteral = {
variable: "I'm a string",
fun: function(param) {
console.log("I'm a function.");
console.log("Here's the param: ", param);
}
}
console.log(objectLiteral);
objectLiteral.fun();
fun
和variable
是对象文字的字段
function()
语法用于声明一个函数,该函数将分配给fun
。