showing results for - "javascript create class"
Eleonora
09 Feb 2019
1class ClassMates{
2	constructor(name,age){
3    	this.name=name;
4      	this.age=age;
5    }
6  	displayInfo(){
7    	return this.name + "is " + this.age + " years old!";
8    }
9}
10
11let classmate = new ClassMates("Mike Will",15);
12classmate.displayInfo();  // result: Mike Will is 15 years old!
Lev
30 Apr 2019
1class Person {
2 constructor(name, age) {
3   this.name = name;
4   this.age = age;
5 }
6  present = () => { //or present(){
7  	console.log(`Hi! i'm ${this.name} and i'm ${this.age} years old`) 
8  }
9}
10let me = new Person("tsuy", 15);
11me.present();
12// -> Hi! i'm tsuy and i'm 15 years old.
Edoardo
21 Nov 2018
1// Improved formatting of Spotted Tailed Quoll's answer
2class Person {
3	constructor(name, age) {
4		this.name = name;
5		this.age = age;
6	}
7	introduction() {
8		return `My name is ${name} and I am ${age} years old!`;
9	}
10}
11
12let john = new Person("John Smith", 18);
13console.log(john.introduction());
Owain
10 Jan 2019
1class Rectangle {
2  constructor(height, width) {
3    this.height = height;
4    this.width = width;
5  }
6  // Getter
7  get area() {
8    return this.calcArea();
9  }
10  // Method
11  calcArea() {
12    return this.height * this.width;
13  }
14}
15
16const square = new Rectangle(10, 10);
17
18console.log(square.area); // 100
Rafael
09 May 2020
1function Animal (name) {
2  this.name = name;
3}
4
5Animal.prototype.speak = function () {
6  console.log(`${this.name} makes a noise.`);
7}
8
9class Dog extends Animal {
10  speak() {
11    console.log(`${this.name} barks.`);
12  }
13}
14
15let d = new Dog('Mitzie');
16d.speak(); // Mitzie barks.
17
18// For similar methods, the child's method takes precedence over parent's method
19
queries leading to this page
javascript new classmake a class in javascriptclass example javascriptwhat is class in jsjavascript custom class objectsjavascript class explainedjs make classdefine a class in java scriptclassess javascriptnew class jshow to make a class in javascript with methodsclass method javascriptjs class functionsexample class definition javascriptclass object javascriptdefining class jsjavascript classiclass methods javascriptvanilla js create classnode js class variable initializedifferent ways of writting methods in a class in jshow to make js classes6 classes javascriptclassses in javascriptjavscript classwhat is a class in javascriptjavascript classjavascript declaring classesjavascript class examplecreating classes in javascriptjs how to use classesjavacsript classcreate class in hjsbasic js classhow to define a function in javascript classfunction class in jsjavascript class objectjs class syntaxhow to make class in javascriptsetting up a class in javascripttype of class obkject jsclass in java scriptjs class initclass javascript defineclass javscriptjs classclass constructor jses6 classhow to build a class in javascriptclass jscreate javascript classnode js class examplejava script create classjs class htmljavascript classes w3schoolsclass of object in javascriptjava script classclass declaration in javascriptjavascript classesclass in javascript examplecreate new class jsjavascript create classfunction class javascriptclasses javascriptjavascrpt classhow do i make a class in javascriptclass declaration in javascript old version class 28 7bnew class object jsjavascript calssjs class variablecreating a class in javascriptclass syntax javascripthow to declare a class in javascriptdefine class jscreating a class in node jscreate js cllasshow to make a simple class in javascriptjavascript es6 classcreate a js classjs declare classjs class objectjs classsmaking a class in javascwrite class in jscreate classin jsjs create classcreate class with function javascriptclass js exampleclass in js with methodshow to write class in javascriptcreate class in javascriptjava script classesclass with jsclass 28 29 javascriptjavascritp classjavascript class to create objectjavascript create custom classclass in jshow to create a user class in javascripthow to make a class in jsjs class w3schoolsjs create class with functionshow to use this in class in jscreate class person javascriptjavascript define a class javascript classhow to make a javascript classjavescript classclass definition javascript examplejs classeswhat is class javascriptfunction class in javascriptclasses in javascriptjavascript class syntaxclass example jsclass in js examplejavascript create class with functionsmethod in class javascripthow to write a class in javascripthow to create a javascript classhow to make class with function in javascriptjavascript declare instance of classjavascript class membersjs class constructorjs class thisjavscript create classcreate class in jsclass syntax in javascriptcreate class jsjs class methodhow to create a class in javascriptcreation classe javascripthow to create a class in jshtml how to use class javascriptusing class with javascriptjavascript class definitionjavascript class attribute declarationw3schools class javascriptcreate class javascriptcreate class javacriptclasses nodejsclasses jsmethod for class js keywordjs function classjavascript class inititinlzitejs new classhow to define a class in javascriptdeclaring a class in javascriptnode init classhow to create class in javascriptjavascript make a classclassi javascriptcreate variables in conscructor of class javascriptdefine a class in jshow to use js classesdoes javascript have classesmethode in class in jsdeclare class javascripthow to define class in javascriptnodejs classw3c javascript classclass example in javascriptjavascript class functionswrite a class javascriptclass and the constructor javascriptsimple javascript classclass javascript 5cclasses in jsjs class member variablejavascript class methodcreate a class in jsjs constructor classwriting classes in javascriptcreate a class in javascriptjavascript 2b classjavascirpt classjavascript declare classcreate class object in javascriptnode js class constructorjavascript class functionclass en javascriptjavascript make classusing javascript classjavascript how to make a classjavascript class declarationjavascript class examplesconstructor in node js classhow to make class in jsjavascript create classjs declare class variablejavascript new class objecthow to code a class in javascriptjs example classesdefine class in javascriptjavascript how to use classhow to make class jscreating class in javascripthow to create class in jsjs class exampleclass javascript examplejs classessjs classes methodsclass in javascriptclass javascriptcreate js classexample class in jscreate class function javascriptbasic class in jsnode js classhow to use class in javascripthow to make a class in javascriptobject class javascriptcreate a class in javascript es6javascript how to write a classclass syntaxjs basic classhow tlo make and use classes in jsclass function jses6 class constructorjavascript create class