tom
0
Q:

call function javascript


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

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"
 
3
// Define your function
function sayHello(msg){
	console.log("Hello, " + msg);
}

// Call it
sayHello("Norris");

// outputs:
// Hello, Norris
2

var person = {

  firstName:"John",

  lastName: "Doe",

    fullName: function () {

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

    }

}

	person.fullName();   // Will return "John Doe"
 
2
function abc() {
  alert('test');
}

var funcName = 'abc';

window[funcName]();
0
<!-- Answer to: "call javascript function from html" -->

<!-- Just call it from a <script> tag: -->

<!--
JavaScript:
  function heyFunc(a) {
	console.log(`Hello ${a}!`);
  };
-->


<marquee>
  Hello!
  <script>heyFunc(World);</script> <!-- Returns: "Hello World!" -->
</marquee>
-1

New to Communities?

Join the community