създаване на обект javascript
let obj = {
// fields
name:"value",
num: 123,
//methods
foo: function(){}
}
обекти javascript
function Dog() {
this.name = "Bailey";
this.colour = "Golden";
this.breed = "Golden Retriever";
this.age = 8;
}
направете обект javascript
class ObjectLayout {
constructor() {
this.firstName = "Larry"; //property
}
sayHi() { // Method
return `Hello from ${this.firstName}`;
}
}
const object = new ObjectLayout();
// object.firstName is Larry;
// object.sayHi() gives "Hello from Larry"
javascript се създава нов обект
person = new Object();