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

access the prototype of an object javascript


var f = function();
var instance = new f();

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

access the prototype of an object javascript

Object.getPrototypeOf(x);

//Output
ƒ () { [native code] }
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add variables to an array in javascript 
Javascript :: destructuring js 
Javascript :: react-bootstrap sidebar menu 
Javascript :: nodejs: express: package for Router 
Javascript :: react.dom 
Javascript :: why we use react js 
Javascript :: node express chat app 
Javascript :: javascript array remove last 
Javascript :: find vs filter 
Javascript :: javascript best online game engine 
Javascript :: jwt decode 
Javascript :: unexpected end of json input 
Javascript :: rxjs of 
Javascript :: mongodb rename property 
Javascript :: ts base64 from file 
Javascript :: how to delete object in array 
Javascript :: private routing in react 
Javascript :: + javascript 
Javascript :: javascript problems 
Javascript :: javascript join 2 variables into string 
Javascript :: cross browser testing 
Javascript :: express multer 
Javascript :: Query MongoDB - Node.js 
Javascript :: lettre au hasard javascript 
Javascript :: JavaScript is case-sensitive 
Javascript :: dynamic key in javascript object 
Javascript :: react router refreshes page 
Javascript :: get x y z position of mouse javascript 
Javascript :: react native store sensitive data in redux 
Javascript :: html check template browser 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =