Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript Create Multiple Objects with Constructor Function

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

     this.greet = function () {
        console.log('hello');
    }
}

// create objects
const person1 = new Person();
const person2 = new Person();

// access properties
console.log(person1.name);  // John
console.log(person2.name);  // John
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check if url returns 200 
Javascript :: preview upload image js 
Javascript :: mssql node js documentation 
Javascript :: javascript count no of lines 
Javascript :: how to make back button react 
Javascript :: $q.platform.is.mobile 
Javascript :: add table row jquery 
Javascript :: copy link to clipboard 
Javascript :: define an unsigned int js 
Javascript :: formdata append not working 
Javascript :: settimeout in loop javascript 
Javascript :: canactivate angular 
Javascript :: window load 
Javascript :: how to start a node server 
Javascript :: add class with javascript 
Javascript :: javascript loop object 
Javascript :: vue.js 
Javascript :: js array last element get 
Javascript :: how to get the size of the window in javascript 
Javascript :: js loop backwards 
Javascript :: getdisplaymedia screenshot 
Javascript :: module is not defined eslint 
Javascript :: response.json() promise pending 
Javascript :: display toastr success 
Javascript :: Converting string to json object 
Javascript :: Moment.js: Date between dates 
Javascript :: js does object contain value 
Javascript :: cart page route in shopify 
Javascript :: Using Regular Expressions (regex) to Print JavaScript Number Format with Commas 
Javascript :: generate random string with javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =