Last active
August 29, 2015 14:21
-
-
Save jucrouzet/428f70d8ed2b5a0ec672 to your computer and use it in GitHub Desktop.
Examples used during the ES6/7 presentation at 42
This file contains 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
=Examples used during the ES6/7 presentation at 42= |
This file contains 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
// String.prototype.includes(substring, startingAt) | |
'Hello world'.includes('wor') // true | |
'Hello world'.includes('hell') // false, sensible à la casse | |
'Hello world'.includes('Hello', 1) // false, on commence à 1 | |
// String.prototype.startsWith(substring, startingAt) | |
'42, born to code'.startsWith('42') // true | |
'42, born to code'.startsWith('foo') // false | |
'42, born to code'.startsWith(42, 1) // false, on commence à 1 | |
// String.prototype.endsWith(substring, startingAt) | |
'42, born to code'.endsWith('code') // true | |
'42, born to code'.endsWith('born') // false | |
'42, born to code'.endsWith('code', 5) // false, on arrete à 5 | |
// Exemple equivalent es5 | |
String.prototype.startsWith = function(substring, startingAt) { | |
startingAt = (startingAt) ? startingAt : 0; | |
return (this.indexOf(substring) === startingAt); | |
}; |
This file contains 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
//test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment