On this page
- 1 JavaScript: Scope and the Variable this
- 2 JavaScript: Scope and the Variable this
- 2.0.0.1 Introduction to the DOM
- 2.0.0.2 How to apply CSS to iframe?
- 2.0.0.3 JavaScript Map, Reduce, and Filter
- 2.0.0.4 JavaScript Concepts Everyone Should Learn!
- 2.0.0.5 JavaScript: localStorage and sessionStorage
- 2.0.0.6 JavaScript: Array functions/methods
- 2.0.0.7 JavaScript: Array map() Method
- 2.0.0.8 Promise in JavaScript with example
- 2.0.0.9 JavaScript: FormData
- 2.0.0.10 JavaScript: How ES6 Arrow Function Can Help You
- 2.0.0.11 ES6: Spread syntax
- 2.0.0.12 ES6: Spread operator
- 2.0.0.13 ES6: Introduction
- 2.0.0.14 JavaScript: Get Element
- 2.0.0.15 JavaScript: JSON (JavaScript Object Notation)
- 2.0.0.16 JavaScript: Application programming interface (API)
- 2.0.0.17 Javascript : Date & Time Program
- 2.0.0.18 JavaScript: What is AJAX?
- 2.0.0.19 JavaScript: Getting started
- 2.1 One Comment
- 2.2 Leave A Comment Cancel reply
JavaScript: Scope and the Variable this
JavaScript: Scope and the Variable this
February 29, 2020
var x = 'hello, world!'; // this is in the global scope! //////////////////// function greet(thing) { console.log(this + " says greetings, " + thing); } greet.call("Cami", "earthlings") // Cami says greetings, earthlings //////////////////// var person = { name: "Samantha", greet: function(thing) { console.log(this + " says greetings, " + thing); } } person.greet('neighbor'); // Samantha says greetings, neighbor person.greet.call(person, 'neighbor'); // Samantha says greetings, neighbor //////////////////// function greet2(thing1, thing2) { console.log(this + " says greetings, " + thing1); console.log("But " + thing2 + " doesn't like " + this); } greet2.call('Samantha', 'Maya', 'Angelina') // Samantha says greetings, Maya // But Angelina doesn't like Samantha greet2.apply('Samantha', ['Maya', 'Angelina']) // Samantha says greetings, Maya // But Angelina doesn't like Samantha //////////////////// var boundGreeting = greet2.bind('Noah') boundGreeting('Christian', 'Ben') // Noah says greetings, Christian // But Ben doesn't like Noah
Hello! I could have sworn I’ve been to this blog before but after reading through some of the post I realized it’s new to me.
Nonetheless, I’m definitely happy I found it and I’ll be book-marking and checking back often!