+ 25
How to make class inheritance in Javascript?
Someone has a simple example
17 Antworten
+ 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
+ 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
+ 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*/
+ 2
Thanks for share that
+ 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.
+ 1
I don't understand anything, but oh well, I still move ahead positively.
+ 1
anyone help :(( can someone help me how to get the perimeter of the square on c++
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);
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 .
0
oh yeah
- 2
yuoobe mp3
- 2
ozuna
- 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.
- 3
hi everybody,good day, good morning,good afternoon, I will say something about it letter
- 4
hi