私下封装其对象数据

时间:2015-02-02 20:43:24

标签: javascript tdd jasmine

请告知。完成http://testfirst.org/learn_javascript - 停留在07_temperature最后一个规范:

这是我的代码:

function Temperature(value){

this.fahrenheit = function(){
    if(this.fahrenheit_value===undefined){
        this.fahrenheit_value = Math.fround(this.celsius_value*1.8 + 32,2);
    }
    return this.fahrenheit_value;
};

this.setFahrenheit = function(value){
    this.fahrenheit_value = value;
};

this.celcius = function(){
    if(this.celsius_value===undefined){
        this.celsius_value = Math.round((this.fahrenheit_value-32)/1.8);
    }
    return this.celsius_value;
};

this.setCelcius= function(value){
 this.celsius_value = value;
};
}

我试图通过的规范如下,我不知道如何通过最后一个"私下封装其数据"。

describe("the Temperature object", function() {
    it("privately encapsulates its data", function() {
        var temperature;
        temperature = new Temperature(32);
        for (var property in temperature) {
            // This assures that there are no data values at all on the object, just methods
          console.log(temperature[property]);
          expect(typeof(temperature[property])).toEqual('function');
        }
    });
});

0 个答案:

没有答案