Let’s talk about THIS

LA TRAMPA

Concepto de propietario

console.log(miObject.fullName)

PATRONES DE INVOCACIÓN

Invocación como método

Console.log(miObject.fullName()) // Aida Albarrán

Invocación como función. Método bind y Arrow Functions

miObjectFunctionPattern.fullName("Albarrán");
console.log(miObjectFunctionPattern.name) // Aida
miObjectFunctionPattern.fullName("Albarrán");
console.log(miObjectFunctionPattern.name) // Aida Albarrán

Invocación como constructor

console.log(myObjectFunction.name) // myObjectFunction
console.log(myObjectFunction.toString()) // function (parameter1, parameter2) {
console.log(`Mi función imprime ${parameter1} y ${parameter2}`);
}
var otherObject = new MyObjectFunction();
otherObject.showFullName(); // Imprime nombre completo: Aida Albarrán
var objectWithClass = new myClassObjectFunction()
objectWithClass.showFullName(); // Imprime nombre completo: Aida Albarrán

Invocación con call y apply

otherObject.showFullName.call(myOtherObject)
Imprime nombre completo: María Gutiérrez

Conclusión

--

--

--

If something does not work, ACT. Yes, you! That’s why I’m now #Developer at @vmware . Formerly @kairos_ds .Constantly absorbing knowledge. Proud #Adalaber

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aida

Aida

If something does not work, ACT. Yes, you! That’s why I’m now #Developer at @vmware . Formerly @kairos_ds .Constantly absorbing knowledge. Proud #Adalaber

More from Medium

Don’t worry, it’s Jest a test

JS學習筆記(1)

Masking Uploaded File Name

Blind 75| Group Anagrams javascript solution (string sorting approach)