Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The real difference is when you add functions into the mix, lets say you want to perform an operation on the data.
- //This could be a simple as turning it into a format or saving it to the server. The thing is, it is a lot easier when
- //You use classes as data Models.
- function Foo(a, b){
- var self = this;
- self.a = a;
- self.b = b;
- self.turnIntoFormat = function(){
- return a + ": " + b;
- };
- }
- var data = [new Foo("a", "b"), new Foo("aa", "bb")];
- //VS this, which is easier?
- var data = [
- {
- "a": "a",
- "b": "bb",
- turnInfoFormat: function(){
- return a + ": " + b;
- };
- },
- {
- "a": "aa",
- "b": "bb",
- turnInfoFormat: function(){
- return a + ": " + b;
- };
- }
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement