Skip to content

Instantly share code, notes, and snippets.

@cazetto
Created November 21, 2016 02:32
Show Gist options
  • Save cazetto/ef534513885d77df82cb165d14385135 to your computer and use it in GitHub Desktop.
Save cazetto/ef534513885d77df82cb165d14385135 to your computer and use it in GitHub Desktop.
var myself = { firstname: 'André ', lastname:'Pesci Cazetto' };
function showFullName(textparam = 'Text Param', numberparam = 10) {
console.log(this.firstname, this.lastname, textparam, numberparam);
}
showFullName.call(myself);
showFullName.apply(myself);
// Call passa os parâmetros na sequência
showFullName.call(myself, 'Texto Parametro PTBR', '220');
// Apply passa os parâmetros numa array
showFullName.apply(myself, ['Texto Passado por array no aply', 30]);
--------
for (var i = 1; i <= 10; i++) {
(function (n) {
var timeout = setTimeout(function () {
console.log(n);
}, i*1000);
})(i);
}
---------
console.log(this); // ReactComponent OK!
function functionName() { return this; }
console.log(functionName()); // undefined UHN!
console.log( functionName.apply(this) ); // waaaat?
----------
var context = 'global';
var object = {
context: 'object',
method: function () {
function func () {
var context = 'context';
return this.context;
}
return func();
}
};
console.log(object.method());
----------
class Thing {
someMethod() {
return this.otherMethod() + ' Yes! Class corresponds to Object.prototype!';
}
}
Thing.prototype.otherMethod = function () {
return 'It is a method of the class?';
};
var thing = new Thing();
thing.someMethod();
function functionName() {
}
console.log(typeof(Thing), typeof(functionName));
console.log(thing instanceof Thing);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment