Hello guys.
I see that a lot of peoples are concerned about the change of the language from to ruby to JS, and how to program with class and inheritance with JS. Well, there are N workarounds that you can implement similar OOP with javascript, the most flexible language that I already seen, this is at the same time the weakness and strength of this language.
I would like to share my favourite way to implement OOP in Javascript, and for this I use the http://jsclass.jcoglan.com library (you just need to use the file "core.js" of his library)
With it, you can define classes like this:
var Animal = new Class({ initialize: function(name) { this.name = name; }, speak: function(things) { return 'My name is ' + this.name + ' and I like ' + things; }});var nemo = new Animal('Nemo'); // nemo.name == "Nemo" nemo.speak('swimming'); // -> "My name is Nemo and I like swimming"And inheritance look like this:
var Dog = new Class(Animal, { speak: function(stuff) { return this.callSuper(stuff).toUpperCase() + '! BARK! BARK!'; }});var rex = new Dog('rex');rex.speak('BONES'); // -> "MY NAME IS REX AND I LIKE BONES! BARK! BARK!"More information is on the library site: http://jsclass.jcoglan.com
I see that a lot of peoples are concerned about the change of the language from to ruby to JS, and how to program with class and inheritance with JS. Well, there are N workarounds that you can implement similar OOP with javascript, the most flexible language that I already seen, this is at the same time the weakness and strength of this language.
I would like to share my favourite way to implement OOP in Javascript, and for this I use the http://jsclass.jcoglan.com library (you just need to use the file "core.js" of his library)
With it, you can define classes like this:
var Animal = new Class({ initialize: function(name) { this.name = name; }, speak: function(things) { return 'My name is ' + this.name + ' and I like ' + things; }});var nemo = new Animal('Nemo'); // nemo.name == "Nemo" nemo.speak('swimming'); // -> "My name is Nemo and I like swimming"And inheritance look like this:
var Dog = new Class(Animal, { speak: function(stuff) { return this.callSuper(stuff).toUpperCase() + '! BARK! BARK!'; }});var rex = new Dog('rex');rex.speak('BONES'); // -> "MY NAME IS REX AND I LIKE BONES! BARK! BARK!"More information is on the library site: http://jsclass.jcoglan.com