Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

prototype in javascript class

// prototype in javascript class
// To declare a class, you use the class keyword with the name of the class ("Rectangle" here).
class Rectangle {
  constructor(w, h) {
    this.w = w;
    this.h = h;
  }
}

// adds an 'area' method to the Rectangle class' as prototype
Rectangle.prototype.area = function () {
  return this.w * this.h;
};

// create an instance of class
const findAreaOfRectangle = new Rectangle(8,3);
// invoke the area method
console.log(findAreaOfRectangle.area()); // Output: 24
Comment

javascript class prototype

A prototype simply does a method of that specific class, it is called a method because it is inside the class but after all it does a function
Comment

PREVIOUS NEXT
Code Example
Javascript :: concatenate strings jsonata 
Javascript :: nestjs optional guard 
Javascript :: use ES6 import syntax when you enhance the script tag 
Javascript :: New year chaos solution 
Javascript :: javascript filter in place algorithm 
Javascript :: mongoose undo delete 
Javascript :: remove json parameter 
Javascript :: javascript pure ajax promise 
Javascript :: jquery textfill example 
Javascript :: remove post via ajax 
Javascript :: how to see a mongo document in a pretty mode 
Javascript :: nuxt js index.html not found 
Javascript :: add attribute jquery 
Javascript :: cd doesn’t work inside childProcess 
Javascript :: js hit asp button onclick event 
Javascript :: Full form of BOM in Javascript is 
Javascript :: blockchain.info/pushtx/ 
Javascript :: SH1 in react native 
Javascript :: fetch Mongodb find() results with Backbone 
Javascript :: How to Compare Strings Using Mathematical Operators 
Javascript :: createTextRange code example 
Javascript :: GridFs Schema 
Javascript :: Automatic update javascript fileversion 
Javascript :: Include Id In Backbone 
Javascript :: javascript foreach next item 
Javascript :: react native scan network 
Javascript :: axios params onclick function 
Javascript :: rpushx redis 
Javascript :: normalisation in js 
Javascript :: advanced javascript concepts 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =