Coder Social home page Coder Social logo

Comments (6)

RealWeeks avatar RealWeeks commented on August 12, 2024

Added and will use this terminology. "Message sent to object" is there a better way to state this?

from js-function-context-this.

jrhorn424 avatar jrhorn424 commented on August 12, 2024

Nothing occurs to me. That's the terminology I've used and other use as well. @gaand any suggestions?

I think 3 is technically wrong from a pure OOP standpoint, but I've heard it used.

from js-function-context-this.

RealWeeks avatar RealWeeks commented on August 12, 2024

This was added in a previous commit. Please don't close, this commit is useful in preparation.

from js-function-context-this.

MicFin avatar MicFin commented on August 12, 2024

@jrhorn424
@gaand asks "Method is called with object as context"?

from js-function-context-this.

MicFin avatar MicFin commented on August 12, 2024

I believe we are referencing the Here we would say sections of the The Four Patterns of Invocation (snippets shown below). I also like the phrasing by @raq929 suggested here that uses the names of the functions and used in example 3 below. The Here we should say phrasing should be consistent though and currently it is not.

1. Function Invocation Pattern

const goBoom = function() {
    console.log('this is ', this);
}
goBoom();

Here we would say "A method is called on an object". In this case the object is the window.

2. Method Invocation Pattern

let deathstar = {
    goBoom: function() {
      console.log('this is ', this);
  }
};

deathstar.goBoom();

Here we would say "Method is called with object as context"

3. Call/Apply Invocation Pattern

const goBoom = function () {
  console.log("this refers to ", this);
};
let deathstar = {
  weapon: 'Planet destroying laser'
};
goBoom.call(deathstar);

Here you would say "Call the function goBoom with deathstar as the context (this)"

4. Constructor Invocation Pattern

const Deathstar = function (weapon) {
  console.log("this is ", this);
  this.emporer = "Darth Sidius";
  this.weapon = weapon;
  this.whatIsThis = function(){
    console.log("Inside whatIsThis, this is ", this);
  };
  console.log("this is ", this);
};

let thatsNoMoon = new Deathstar('Mega giant huge laser');
let endor = new Deathstar('Happy little Ewoks');

Here we would say "the object receives the method".

from js-function-context-this.

raq929 avatar raq929 commented on August 12, 2024

This was partially but not fully addressed for 016.

from js-function-context-this.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.