11 Answers
New Answerstandard: 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
... 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
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message