Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

.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.
Comment

js create and call function

// Create a function (you decide the name) that logs out the number 42 
// to the console

// Call/invoke the function

 function number(){
     console.log(42)
 }
 
 number()
//result = 42
Comment

javscript call

myFunc.call(thisArg, ...args)
Comment

how to call a function in JavaScript

// calling our function
displayGreeting();
Comment

how to call a function javascript

//  we create a function by typing the keyword " function" + Function's name and ( we add the parameter here )
// {
//     the function body 
// }

// we call the function by typing it's name without the keyword and we add ()

function second (name){ 
    name = "Elmustafa";
    alert(name);
}

first();
Comment

javascript call

function myFunc(p1, p2, pN)
{
     // here "this" will equal "myThis"
}
let myThis = {};

// call myFunc using myThis as context.
// pass params to function arguments.
myFunc.call(myThis, "param1", "param2", "paramN");
Comment

JavaScript Function call()

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

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

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
Comment

The JavaScript call() Method


		const person = {
name: "John Smith",
getNameAndAddress: function(city, country)
{
return this.name+city+country;
}

}
const personWithoutGet = {
name: "Jerry Smithers"}

 console.log(person.getNameAndAddress.call(personWithoutGet, 'Berlin','Germany'));
/*you can think of bind(), apply() and call() ALL as "stealing someone else's function to use."*/
/* victimBeingStolenFrom.functionName.call(theThief) */
/*notice the second variable personWithoutGet does not have a getName function*/
Comment

javascript call example

l = "abcder";
q = "Ererwrwrewrew";
console.log(String.prototype.substr.call(q, 1, 4))
/*rerw...4 refers to how many characters to substring*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: $Javascript $.get( 
Javascript :: double exclamation mark javascript 
Javascript :: how to multiply two array in javascript 
Javascript :: array reverse 
Javascript :: añadir input file a formdata javascript 
Javascript :: javascript detect if active element is writable 
Javascript :: phaser matter is undefined 
Javascript :: decode jwt token online 
Javascript :: javascript split string into groups of n 
Javascript :: js organise string tab spaced 
Javascript :: transform js to typescript 
Javascript :: ohif add auth to config 
Javascript :: how to check my javascript code 
Javascript :: traversing 2d array javascript 
Javascript :: searchable 
Javascript :: draw image inside canvas width 100% 
Javascript :: mongoose auto delete after time 
Javascript :: laravel onkeyup textbox, get value from span javascript 
Javascript :: hide navbar and footer on certain pages like dashboard. react-router 
Javascript :: angular create spec file for existing component 
Javascript :: Angularjs $on called twice 
Javascript :: Presenting backend data using AngularJS/AJAX in MVC VIEW 
Javascript :: How to add the items from a array of JSON objects to an array in Reducer 
Javascript :: adding to an array in js 
Javascript :: JOLT split flat object into key/value array 
Javascript :: TypeError: table.fnFilter is not a function 
Javascript :: Variables In Self Invoking Function 
Javascript :: javasrccipt loop array 
Javascript :: creating hashblock method using sha256 hashing algorithm 
Javascript :: react router how to prevent navlink from two classes 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =