Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript Changing Prototype

// constructor function
function Person() {
    this.name = 'John'
}
// add a property
Person.prototype.age = 20;
// creating an object
const person1 = new Person();

console.log(person1.age); // 20

// changing the property value of prototype
Person.prototype = { age: 50 }

// creating new object
const person3 = new Person();

console.log(person3.age); // 50
console.log(person1.age); // 20
Comment

Changing Prototype

// constructor function
function Person() {
    this.name = 'John'
}

// add a property
Person.prototype.age = 20;

// creating an object
const person1 = new Person();

console.log(person1.age); // 20

// changing the property value of prototype
Person.prototype = { age: 50 }

// creating new object
const person3 = new Person();

console.log(person3.age); // 50
console.log(person1.age); // 20
Comment

PREVIOUS NEXT
Code Example
Javascript :: telerik jquery grid trigger editcell 
Javascript :: Error: Minified React error #321 
Javascript :: ticket draw 
Javascript :: Can Execute Backbone In RequireJS 
Javascript :: react axios project importing online same products with table from fake API 
Javascript :: Mirror Inverse Program in javascript 
Javascript :: check if a specific user is banned discord js 
Javascript :: save slug on schema pre save in node js 
Javascript :: Get Error 
Javascript :: get a nodes path alias 
Javascript :: javascript online string concatenation 
Javascript :: lwc reduceErrors showtoast 
Javascript :: ajax file upload 
Javascript :: hide header on button click in react native 
Javascript :: vite displays blank page in docker container 
Javascript :: react leaflet layer disable controls while on top 
Javascript :: jquery remove duplicates 
Javascript :: array reverse 
Javascript :: phaser matter is undefined 
Javascript :: how to get a set of values in mogodb 
Javascript :: multply js 
Javascript :: generate html by javascript 
Javascript :: alert title change 
Javascript :: draw image inside canvas width 100% 
Javascript :: angular universal prerender 
Javascript :: javascript Scroll into a div that is hidden initially in react 
Javascript :: Changing the value of a dropdown when the value of a number box changes in AngularJS 
Javascript :: Angularjs - Deep Orderby - How to handle multiple layers of sorting 
Javascript :: react-native navigation stack set push component then cover parent page 
Javascript :: adding to an array in js 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =