Javascript Hint for Class and Inheritance

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
Underscores Extend method would be better  in this case unless you are using ES6 then I would recommend writing:

Code:
class LogView extends View {  render() {    var compiled = super.render();    console.log(compiled);  }}// You can read more at: [URL="http://javascriptplayground.com/blog/2014/07/introduction-to-es6-classes-tutorial/%C2%A0"]http://javascriptplayground.com/blog/2014/07/introduction-to-es6-classes-tutorial/ [/URL]

Original thread: https://forums.rpgmakerweb.com/threads/javascript-hint-for-class-and-inheritance.45593/