Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript Constructor Function Parameters

// constructor function
function Person (person_name, person_age, person_gender) {
   // assigning  parameter values to the calling object
    this.name = person_name,
    this.age = person_age,
    this.gender = person_gender,
   this.greet = function () {
        return ('Hi' + ' ' + this.name);
    }
}


// creating objects
const person1 = new Person('John', 23, 'male');
const person2 = new Person('Sam', 25, 'female');

// accessing properties
console.log(person1.name); // "John"
console.log(person2.name); // "Sam"
Comment

JavaScript Constructor Function Parameters

// constructor function
function Person (person_name, person_age, person_gender) {

   // assigning  parameter values to the calling object
    this.name = person_name,
    this.age = person_age,
    this.gender = person_gender,

    this.greet = function () {
        return ('Hi' + ' ' + this.name);
    }
}


// creating objects
const person1 = new Person('John', 23, 'male');
const person2 = new Person('Sam', 25, 'female');

// accessing properties
console.log(person1.name); // "John"
console.log(person2.name); // "Sam"
Comment

PREVIOUS NEXT
Code Example
Javascript :: JavaScript Changing Prototype 
Javascript :: javascript Access String Characters 
Javascript :: JavaScript Number Properties 
Javascript :: javascript modules 
Javascript :: javascript Multiline Strings Using Template Literals 
Javascript :: javascript WeakSets Are Not iterable 
Javascript :: javascript setTimeout() method returns the interval id 
Javascript :: javascript Deleting an object is not allowed 
Javascript :: what is package.josn file 
Javascript :: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. 
Javascript :: return object from array by property value 
Javascript :: jquery if each checkbox is checked push array using each site:stackoverflow.com 
Javascript :: Photoshop extendscript javascript save to text file a list of layers 
Javascript :: divide array in chunks 
Javascript :: Warning: Problem validating app.json: Unable to perform cache refresh for 
Javascript :: how to generate random 6 digit charecter in js for coupon 
Javascript :: phaser create animation from canvas texture 
Javascript :: get lat long react native 
Javascript :: _.isUndefined 
Javascript :: node transitions 
Javascript :: prevent alpine js from rendering components during refresh 
Javascript :: Use Prototype To Add A Property To Javascript Class 
Javascript :: compare text 
Javascript :: filter 
Javascript :: how to assign an rest operator in javascript 
Javascript :: define function javascript 
Javascript :: material-ui add icon to switch when on 
Javascript :: python json replace string 
Javascript :: .remove javascript 
Javascript :: preview file before upload in react 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =