Q:

how do i call a js method?


var person = {

    fullName: function() {

    return this.firstName + " " + this.lastName;

    }
}

var person1 = {

  firstName:"John",

    lastName: "Doe"

  }

var person2 = {

  firstName:"Mary",

    lastName: "Doe"
}

  person.fullName.call(person1);  // Will return "John 
  Doe"
 
1
function runFunction() {
  myFunction();
}

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

runFunction();
1
<button onclick="sayHello()">say hello</button>  <script>    'use strict';  //force the context to be undefined    function sayHello() {      console.log(this);      console.log(arguments);      console.log('hello');    }  </script>
-1

New to Communities?

Join the community