Last active
August 29, 2015 13:56
-
-
Save Magomogo/9002316 to your computer and use it in GitHub Desktop.
JS data types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$http.get('hostname/remote/service').success(function (data) { | |
// this way we document remote data type | |
var resultInterval = new DateInterval(data); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
module.exports = function () { | |
var state = arguments[0] || {}; | |
return Object.seal({ | |
id: state.id, | |
name: state.name | |
}); | |
}; | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Hotel = require ('./Hotel.js'), | |
hotelArosa = new Hotel({ | |
id: '123456', | |
name: 'Hotel Arosa' | |
}), | |
newHotel = new Hotel(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
function DateInterval() { | |
var state = arguments[0] || {}; | |
Object.defineProperties(state, { | |
"from": { | |
value: state.from, | |
writable: true, | |
enumerable: true | |
}, | |
"to": { | |
value: state.to, | |
writable: true, | |
enumerable: true | |
} | |
}); | |
return Object.seal(state); | |
} | |
var i1 = new DateInterval(), | |
i2 = new DateInterval({from: '2014-01-02', to: '2014-01-03'}); | |
// mutable | |
i1.from = (new Date()).toJSON(); | |
i1.to = (new Date()).toJSON(); | |
console.log(i1); | |
console.log(i2); | |
// serializable | |
console.log(JSON.stringify(i1)); | |
// protected from accidental mistakes | |
console.log(i1.undefined); | |
i1.newProperty = {}; | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment