Skip to content

Instantly share code, notes, and snippets.

@jucrouzet
Last active August 29, 2015 14:21
Show Gist options
  • Save jucrouzet/428f70d8ed2b5a0ec672 to your computer and use it in GitHub Desktop.
Save jucrouzet/428f70d8ed2b5a0ec672 to your computer and use it in GitHub Desktop.
Examples used during the ES6/7 presentation at 42
=Examples used during the ES6/7 presentation at 42=
// 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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment