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 :: javascript set() handler 
Javascript :: JSON requests using API in Javascript 
Javascript :: fs renameSync 
Javascript :: how to reload automaticaly in vue 
Javascript :: show filed of object javascript 
Javascript :: slice() in js 
Javascript :: react write into json file 
Javascript :: assign freemarker expressions to variables 
Javascript :: jquery connection reset 
Javascript :: nestjs AXIOS_INSTANCE_TOKEN 
Javascript :: prettier overrides 
Javascript :: get contents between tags javascript 
Javascript :: react-multi-carousel infinite loop causing issue 
Javascript :: useEffect() Execute Function When React Component Loads 
Javascript :: how to check element has event or not in jquery 
Javascript :: next js typescript 
Javascript :: display a div only seconds js 
Javascript :: jquery on method 
Javascript :: array.splice 
Javascript :: Material-ui Accessibility icon 
Javascript :: sum up all the first and last digit of a number until only two digits are left 
Javascript :: self-invoking function 
Javascript :: google places autocomplete react native 
Javascript :: javascript assign multiple variables to same value ES6 
Javascript :: toggle function in javascript 
Javascript :: react router hooks 
Javascript :: node express config file json 
Javascript :: javascript detect if the browser tab is active 
Javascript :: react native comment in render 
Javascript :: Alpine.js: button using @click function not working 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =