“.Call JavaScript” Code-Antworten

.Call JavaScript

// Call (borrow) an object's function from another object
// 'this' will bind to the borrower
// syntax: ownerObject.ownerFunction.call(borrowerObject)

const sidekick = {
  name: "Robin"
}

const hero = {
  name: "Batman",
  saveGotham: function() {
    console.log(this.name, "is keeping Gotham safe.");
  }
}
hero.saveGotham(); // Batman is keeping Gotham safe.
hero.saveGotham.call(sidekick); // Robin is keeping Gotham safe.
Intra

Ausführen einer Funktion in einer Funktion JavaScript

function runFunction() {
  myFunction();
}

function myFunction() {
  alert("runFunction made me run");
}

runFunction();
Lava

JavaScript -Funktionsaufruf mit Variable

function abc() {
  alert('test');
}

var funcName = 'abc';

window[funcName]();
vlT

JavaScript -Funktion call ()

const person = {
  firstName:"John",
  lastName: "Doe",
  fullName: function () {
    return this.firstName + " " + this.lastName;
  }
}

// This will return "John Doe":
person.fullName();  
naly moslih

JavaScript Call ()

const personOne = {
  firstName : "Elon",
  secondName : "Musk"
}

const getFullName = function(company, country) {
  console.log(this.firstName + " " + this.secondName + ", " + company + ", " + country);
}

const personTwo = {
  firstName : "Mark",
  secondName : "Zuckerburg"
}

getFullName.call(personOne, "Tesla", "United States");    // outputs Elon Musk, Tesla, United States
getFullName.call(personTwo, "Facebook", "United States");    // outputs Mark Zuckerberg, Facebook, United States
sani sahani

JavaScript Anzahl der Anrufe Funktionen

const counter = ((count = 0) => () => count++)()

Ähnliche Antworten wie “.Call JavaScript”

Fragen ähnlich wie “.Call JavaScript”

Weitere verwandte Antworten zu “.Call JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen