Open jrhorn424 opened 9 years ago
Added and will use this terminology. "Message sent to object" is there a better way to state this?
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.
This was added in a previous commit. Please don't close, this commit is useful in preparation.
@jrhorn424 @gaand asks "Method is called with object as context"?
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".
This was partially but not fully addressed for 016.
Makes calling context clear.