“Métodos de objeto” Respostas de código

Métodos de objeto de verificação javascript

Object.getOwnPropertyNames() 
Clumsy Cobra

Obtenha métodos em um objeto JS

let members = Object.getOwnPropertyNames(foo)
calderwoodra

Métodos de objeto JS

create()
keys()
values()
entries()
assign()
freeze()
seal()
getPrototypeOf()
Anton Grigoriev

Método de objeto em JavaScript

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
Ariful Islam Adil(Code Lover)

Métodos de objeto JavaScript

const person = {
    name: 'Sam',
    age: 30,
    // using function as a value
    greet: function() { console.log('hello') }
}

person.greet(); // hello
SAMER SAEID

Métodos de objeto

//There are 2 main ways to create an Object in JavaScript

//The First Method:
let firstPlayer = new Object();

//You can add properties like this:
firstPlayer.name = 'Player 1';
firstPlayer.level = 3;
firstPlayer.inventory = ['a half-eaten cracker', 'some pocket lint', 'a flimsy tree branch'];
firstPlayer.description = 'Don\'t mention Player 2 around them, they\'ll get angry...';

//You can create methods like this:
firstPlayer.checkLevel = function() {
    console.log(`${this.name} is currently... Level ${this.level}!`);
    //The "this" keyword refers to the object
}

firstPlayer.checkLevel();
//This will print "Player 1 is currently... Level 3!" to the Console


//The Second Method:
let secondPlayer = {
    
    //You can add properties like this:
    name: 'Player 2',
    level: 20,
    inventory: ['a health potion', 'a sack of gold coins', 'a sturdy steel blade'],
    description: 'Better than Player 1 in every way possible.',
    
    //You can create methods like this:
    checkLevel: function() {
        console.log(`${this.name} is currently... Level ${this.level}!`);
        //The "this" keyword refers to the object
    }
}

secondPlayer.checkLevel();
//This will print "Player 2 is currently... Level 20!" to the Console

//And that's it! Decide what method you prefer and start making some Objects!
Minerrian

Respostas semelhantes a “Métodos de objeto”

Perguntas semelhantes a “Métodos de objeto”

Mais respostas relacionadas para “Métodos de objeto” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código