“Warisan prototipe JavaScript” Kode Jawaban

Warisan JavaScript

class Car {
  constructor(brand) {
    this.carname = brand;
  }
  present() {
    return 'I have a ' + this.carname;
  }
}

class Model extends Car {
  constructor(brand, mod) {
    super(brand);
    this.model = mod;
  }
  show() {
    return this.present() + ', it is a ' + this.model;
  }
}

let myCar = new Model("Ford", "Mustang");
document.getElementById("demo").innerHTML = myCar.show();
Clear Cottonmouth

Warisan JavaScript

class Animal {
   null
}
class tiger extends Animal {
 null }
lieutenant-uni

Warisan dalam JavaScript

class teamMember {
    name;
    designation = "Support web dev";
    address;
    constructor(name, address) {
        this.name = name;
        this.address = address;
    }
}

class Support extends teamMember {
    startSession() {
        console.log(this.name, "start a support sessin");
    }
}
class StudentCare extends teamMember {
    buildARoutine() {
        console.log(this.name, "build a routine");
    }
}

const max = new Support("Max", "USA");
console.log(max);
const sarah = new StudentCare("Sarah", "UK");
console.log(sarah);
Ariful Islam Adil(Code Lover)

rantai prototipe dalam javascript

{
    prop: "some value",
    __proto__: {
        foo: "bar",
        constructor: ƒ doSomething(),
        __proto__: {
            constructor: ƒ Object(),
            hasOwnProperty: ƒ hasOwnProperty(),
            isPrototypeOf: ƒ isPrototypeOf(),
            propertyIsEnumerable: ƒ propertyIsEnumerable(),
            toLocaleString: ƒ toLocaleString(),
            toString: ƒ toString(),
            valueOf: ƒ valueOf()
        }
    }
}
Relieved Rook

Warisan JavaScript

function Teacher(first, last, age, gender, interests, subject) {
  Person.call(this, first, last, age, gender, interests);

  this.subject = subject;
}
Valentin Döring

Warisan prototipe JavaScript

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

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

// adding property to constructor function
Person.prototype.gender = 'male';

// prototype value of Person
console.log(Person.prototype);

// inheriting the property from prototype
console.log(person1.gender);
console.log(person2.gender);
SAMER SAEID

Jawaban yang mirip dengan “Warisan prototipe JavaScript”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya