JavaScript -Objektmethoden prüfen
Object.getOwnPropertyNames()
Clumsy Cobra
Object.getOwnPropertyNames()
create()
keys()
values()
entries()
assign()
freeze()
seal()
getPrototypeOf()
objectName.methodname = functionName;
var myObj = {
myMethod: function(params) {
// ...do something
}
// OR THIS WORKS TOO
myOtherMethod(params) {
// ...do something else
}
};
const student = {
id: 101,
major: "Mathamatics",
money: 5000,
name: "Abrar",
subjects: ["English", "Economics", "Math 101", "Calculus"],
bestFriend: {
name: "Kundu",
major: "Mathematics"
},
takeExam: function () {
console.log(this.name, "taking exam");
},
treatDey: function (expense, tip) {
this.money = this.money - expense - tip;
return this.money
}
}
student.takeExam();
//Output: Abrar taking exam
const remaining1 = student.treatDey(900, 100);
const remaining2 = student.treatDey(500, 50);
console.log(remaining1);
console.log(remaining2);
//Output: 4000,3450
const person = {
name: 'Sam',
age: 30,
// using function as a value
greet: function() { console.log('hello') }
}
person.greet(); // hello
const person = {
firstName: "John",
lastName: "Doe",
id: 5566,
fullName: function() {
return this.firstName + " " + this.lastName;
}
};