2015-07-21 54 views
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; 
    } 
}); 
+1

這兩個語句都將函數分配給對象文字鍵。當你調用'defaults'時,它會調用分配的函數。當你調用'domain'時,它會調用其他函數。有關更多信息,請參閱**對象文字** – jasonscript

回答

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(); 

funvariable是對象文字的字段。
function()語法用於聲明一個函數,該函數被分配到fun

相關問題