This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Foo() { | |
this.bar = function() { | |
return this; | |
} | |
} | |
// exemple 1 | |
var foo = new Foo(); | |
console.log(foo); //=> Foo | |
console.log(foo.bar() instanceof Foo); //=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() { | |
return this; | |
} | |
// invocation en tant que fonction | |
foo(); //=> this === window | |
var bar = { | |
'foo': foo | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() {}; | |
foo(); //=> this === window | |
var bar = function() {}; | |
bar(); //=> this === window | |
// ou en notation ES6 | |
var bar = () => {}; | |
bar(); //=> this === window |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// astuce #1 | |
var args = [].slice.call(arguments, 0); | |
// astuce #2 | |
[].forEach.call(arguments, ( x => /* expression */ ) ); | |
// astuce #3 | |
const args = Array.from(arguments); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() { | |
console.log(arguments.length); //=> 3 | |
console.log(arguments); //=> [1,2,'bar'] | |
console.log(arguments[2]); //=> 'bar' | |
console.log(arguments.filter); //=> undefined | |
} | |
foo(1,2,'bar'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fonction1() { | |
var a = 1; | |
function fonction2() { /* ... */ } | |
var b = 2; | |
if (a === 1) { | |
var c = 3; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (true) { | |
var foo = 'bar'; | |
} | |
console.log(foo); //=> 'bar' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dire = function(callback) { | |
alert(callback()); | |
}; | |
// ou en notation ES2015 | |
const dire = (callback) => alert(callback()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dire(callback) { | |
alert(callback()); | |
} | |
function executerAuChargement() { | |
return dire(() => "Bonjour, JavaScript !"); | |
} | |
window.onload = executerAuChargement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dire(callback) { | |
alert(callback()); | |
} | |
function bonjour() { | |
return "Bonjour, JavaScript !"; | |
} | |
function executerAuChargement() { | |
return dire(bonjour); | |
} | |
window.onload = executerAuChargement; |