“Prototyp w JavaScript” Kod odpowiedzi

Prototyp funkcji 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

Prototypowy JavaScript

/*Prototype is used to add properties/methods to a 
constructor function as in example below */

function ConstructorFunction(name){
	this.name = name //referencing to current executing object
}
ConstructorFunction.prototype.age = 18
let objectName = new ConstructorFunction("Bob")
console.log(objectName.age) //18
Coderwhohelps

[[Prototyp]]

var proto = {    describe: function () {        return 'name: '+this.name;    }};var obj = {    [[Prototype]]: proto,    name: 'obj'};
Fancy Fly

Co to jest prototyp JavaScript

* Prototype

-Every object in JavaScript has a built-in property,
which is called its prototype. 

-The prototype is itself an object, so the prototype will 
have its own prototype, making what iss called a prototype chain.

-The chain ends when we reach a prototype that has null for 
its own prototype.

-Prototypes are the mechanism by which JavaScript objects inherit
features from one another

const  arr = [1,2,3,4]

// proto type : arr.__proto__
// prototype chain : arr.__proto__.__proto__.__proto__

Abhishek

Prototyp JavaScript

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

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

Prototyp w JavaScript

/*every object in js inherits properties and methods from it's prototype 
which is itself an object */
var a = {}
console.log(a); //{} empty object with __proto__object.
//when we create object then global object Function is created which can be access by Objectr
Object.prototype.name="Shirshak";
console.log(a) // {} empty object with __proto_object which also contain name varibale which value is shirshak


Shirshak kandel

Odpowiedzi podobne do “Prototyp w JavaScript”

Pytania podobne do “Prototyp w JavaScript”

Więcej pokrewnych odpowiedzi na “Prototyp w JavaScript” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu