OOP with Javascript? | Sololearn: Learn to code for FREE!


OOP with Javascript?

5/5/2018 9:24:03 PM

Cristopher Pereira Moreira

11 Answers

New Answer


standard: function Animal(name, age, type){ this.name = name; this.age = age; this.type = type; } Animal.prototype.getName(){ return this.name; } var dog = new Animal("Snoop", 420, "Dogg"); var pengu = new Animal("Pingu", 69, "Penguin"); //////////////// or by object var Animal = { name: "", age: 0, type: "", getName: function(){ return this.name; }, } var dog = Object.create(Animal); dog.name = "Snoop"; dog.age = 420; dog.type = "Dogg": ///////////// Now theres a class identifier but idk how to use it properly. I prefer oldschool ways


KrOW wow JS class is seriously that easy? Articles complicate it so much xD


KrOW thanks for sharing :)



... and last ES version class form: class Animal{ constructor(name,age,type){ this.name= name this.age= age this.type= type } getName(){ return this.name } }


「HAPPY TO HELP」 While there are some pitfalls, basically its simple ... I have used some of it in my code https://code.sololearn.com/WmDleRRFZ2W7/?ref=app


Really looking forward to browsers in general allowing ES6 & 7 without having to transpile back to ES5. Prototype is OOP but will be nice to have the same language syntax as every other language.




we have few helping posts regarding that in here somewhere but there's a good book as well packt object oriented JavaScript , might find download links on Google for free https://www.sololearn.com/discuss/739193/?ref=app


thanks standard way reflects better for me the object creation


there are cool things with TypeScript and ReactJS thanks guys!