Tuesday, June 4, 2019

[JavaScript][Example] Create object

Result please check console:
{living: true, age: 33, gender: "male", getGender: ƒ}age: 33gender: "male"getGender: ƒ ()arguments: nullcaller: nulllength: 0name: ""prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: (index):38[[Scopes]]: Scopes[2]living: true__proto__: Object
male
---
object
ƒ (living, age, gender){
    this.living = living;
    this.age = age;
  this.gender = gender;
  this.getGender = function(){return this.gender;}
}
female
male

1 comment :

  1. For the Person constructor, it is better to use prototype when defining getGender function, using this method to define getGender function may result in 100 Person object contains 100 getGender method

    ReplyDelete