+ 25

How to make class inheritance in Javascript?

Someone has a simple example

5th Jul 2017, 3:34 PM
Javier I. Rivera R.
Javier I. Rivera R. - avatar
17 Réponses
+ 27
Actually, JavaScript uses a different approach than C# or C++ to create an object-oriented language. It is a prototype-based language. The concept of prototyping implies that behavior can be reused by cloning existing objects that serve as prototypes. Every object in JavaScript decends from a prototype which defines a set of functions and members that the object can use. There is no class. Just objects. Every object can then be used as a prototype for another object. This concept is extremely flexible and we can use it to simulate some concepts from OOP like inheritance. want to learn more about prototype to use inheritance concept here is explanation with example https://www.w3schools.com/js/js_object_prototypes.asp
6th Jul 2017, 2:11 AM
Ant●ny
+ 8
I do not understand .. what happens with class-extends .. it's not to do something like inheritance .. Example of Class and inheritance in JavaScript in ES6 JS class Animal { constructor(name) { this.name = name } talk() { document.write(this.name + 'makes a noise'); } } class Dog extends Animal { talk() { super.talk(); document.write("<br>"); document.write(this.name + ' Guau.'); } } var p = new Dog('Mitzie'); p.talk(); https://code.sololearn.com/WTLc0A3x0G27
6th Jul 2017, 10:11 PM
Javier I. Rivera R.
Javier I. Rivera R. - avatar
+ 4
You asked for a simple example, and I wanted to make sure I understood this before answering anything. https://code.sololearn.com/WsU5B3cugn7C/?ref=app I am just linking this bigger one to show a potential use case (I did this to learn it sufficiently to demo): https://code.sololearn.com/WKLubPzanpv8/?ref=app*/
8th Jul 2017, 1:26 AM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Thanks for share that
6th Jul 2017, 6:37 PM
Shkar ‌H Sardar
Shkar ‌H Sardar - avatar
+ 2
@Viraj Singh ... I use class definitions (constructors + simple methods) in my binary clock: https://code.sololearn.com/W9cfvIzP6T91/?ref=app classes: BinaryClock, LightColumn and Light @ES6ers: Nice surprise I guess, it works for me on a non-ES6 system. @OP: I'll try to think how this could use / I could contribute re: inheritance; just saw a nice video on this.
7th Jul 2017, 6:35 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
I don't understand anything, but oh well, I still move ahead positively.
11th Jul 2017, 12:28 PM
Laurent Kuligha Ambrose
Laurent Kuligha Ambrose - avatar
+ 1
anyone help :(( can someone help me how to get the perimeter of the square on c++
11th Jul 2017, 2:08 PM
Melchor Gaspar Baltazar
Melchor Gaspar Baltazar - avatar
0
Javascript doesn't has classes but since it's an object oriented language, we can create our own objects. As object has properties and methods, we can imitate inheritance by our own methods. function class1 (var name,var2 age) { this.name = name; this.age = age = class1; } function class2() { var v = this.age -4; return v; } var inheritance = new class1("Nikelodeon",69); document.write (inheritance.age);
7th Jul 2017, 9:24 AM
Viraj Singh
Viraj Singh - avatar
0
use ES6 or Typescript for class inheritance, if you know other languages like C++ or C# to you'll like using classes more than working with protos and prototypes .
8th Jul 2017, 4:55 AM
Vazgen Sargisian
Vazgen Sargisian - avatar
0
oh yeah
8th Jul 2017, 12:01 PM
Muneeb Zubair Khan
Muneeb Zubair Khan - avatar
6th Jul 2017, 10:27 PM
KbbLab
- 2
yuoobe mp3
8th Jul 2017, 7:38 PM
Luisalejandro Contreras
Luisalejandro Contreras - avatar
- 2
ozuna
8th Jul 2017, 7:39 PM
Luisalejandro Contreras
Luisalejandro Contreras - avatar
- 3
If you get error, this app still not support for latest javascript/ecmascript. Please go to babel js website, paste your code there in babel js playground.
6th Jul 2017, 10:30 PM
KbbLab
- 3
hi everybody,good day, good morning,good afternoon, I will say something about it letter
10th Jul 2017, 4:21 PM
NURA MUHAMMED
- 4
hi
7th Jul 2017, 5:04 AM
sagheermughal