Skip to content

Instantly share code, notes, and snippets.

@kalisjoshua
Created April 6, 2017 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalisjoshua/7b265b7da994afea852b030964a9ee10 to your computer and use it in GitHub Desktop.
Save kalisjoshua/7b265b7da994afea852b030964a9ee10 to your computer and use it in GitHub Desktop.
Collection of interesting JavaScript syntax.
// 1.
// replace instances with different replacement strings
const qwerty = 'qw#rt#'.replace(/#/g, [].shift.bind(['e', 'y']));
// 2.
// make Array.slice available as a function instead of a method
const slice = Function.prototype.call.bind(Array.prototype.slice);
// 3.
// ASI (failure) working in conjunction with the comma operator
var name = { Goodbye: [1, 2, 3] }
// not an array; bracket notation addressing "Goodbye" property
// of the preceeding object because there is no semi-colon
[ 'Hello', 'Goodbye' ].forEach(function (value) {
// `name` is undefined because `forEach` returns nothing
console.log(`${value} ${name} <br />`)
})
;(function () {
const q = { Goodbye: [1, 2, 3] }[ 'Hello', 'Goodbye' ]
console.log(typeof q, q)
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment