“JavaScript -Objektprototyp” Code-Antworten

JavaScript -Objektprototyp

// 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
SAMER SAEID

Funktionsprototyp JavaScript

function Person(name) {
  this.name = name;
}
Person.prototype.getName = function() {
  return this.name;
}

var person = new Person("John Doe");
person.getName() //"John Doe"
TC5550

JavaScript -Objektprototyp

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

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

  return result;
}
Gazi Jakia Sultana

Greifen Sie auf den Prototyp eines Objekts JavaScript zu


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

Different Dugong

JavaScript -Objektprototypen

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");
naly moslih

Greifen Sie auf den Prototyp eines Objekts JavaScript zu

Object.getPrototypeOf(x);

//Output
ƒ () { [native code] }
Anthony Smith

Ähnliche Antworten wie “JavaScript -Objektprototyp”

Fragen ähnlich wie “JavaScript -Objektprototyp”

Weitere verwandte Antworten zu “JavaScript -Objektprototyp” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen