Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript Object Prototype

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

// creating objects
let person1 = new Person();
let person2 = new Person();

// adding new property to constructor function
Person.prototype.gender = 'Male';

console.log(person1.gender); // Male
console.log(person2.gender); // Male
Comment

javascript object prototype

function listAllProperties(o) {
  let objectToInspect = o;
  let result = [];

  while(objectToInspect !== null) {
    result = result.concat(Object.getOwnPropertyNames(objectToInspect));
    objectToInspect = Object.getPrototypeOf(objectToInspect)
  }

  return result;
}
Comment

JavaScript Object Prototypes

function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
Comment

PREVIOUS NEXT
Code Example
Javascript :: JavaScript HTML DOM Navigation 
Javascript :: status role discord.js 
Javascript :: error:0308010C:digital nextjs 
Javascript :: javascript even/uneven numbers 
Javascript :: The first article title 
Javascript :: jquery callback functions 
Javascript :: nodejs: Basic: managing file: Read, Write, Create, Delete 
Javascript :: javascript get days difference between two dates 
Javascript :: mongoose findbyidandupdate or findoneandupdate 
Javascript :: javascript copy by reference 
Javascript :: alternative for react-tilt 
Javascript :: Json to npy file 
Javascript :: phaser random triangle 
Javascript :: phaser mixed animation 
Javascript :: append input using js 
Javascript :: permissions in chrome extension javascript 
Javascript :: js undici fetch data async 
Javascript :: how to change name on tab when user goes to another tab 
Javascript :: smembers in redis 
Javascript :: string concat in js 
Javascript :: javascript map foreach 
Javascript :: mongoose schema example 
Javascript :: localstorage in next js 
Javascript :: filter bootstrap 
Javascript :: dayjs subtract days 
Javascript :: change url without reloading the page 
Javascript :: react native push notifications npm 
Javascript :: Difference Between for...of and for...in Statement 
Javascript :: spotify player react 
Javascript :: white with opacity rgba to hex 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =