Skip to content

Latest commit

 

History

History

Section11-Closures-and-the-Keyword-this

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Section 11- Closures and the Keyword this

Section Slides

this Keyword

Four Rules for determining

  1. Global Context

    when this is not inside of a declared object its value is the 'window' object (in browser)

    when "use strict"/strict mode this when inside a function or when a variable is declare inside a function it is undefined in the global obj.

  2. Implicit/Declared in Object

    When this is inside of a declared object its value is the closest parent object

  3. Explicit Binding

    • call -> immediately invoked -> fn.call(thisArg,a,b,c...)
    • apply -> immediately invoked -> fn.apply(thisArg,[a,b,c...])
    • bind -> returns a function def -> fn.bind(thisArg,a,b,c,d...)-> useful when using asynchronous functions (or functions called later) and when we do not know the exact arguments
  4. The new keyword

    new keyword when called will create a new object. The this refers to the new object.