Skip to content

Instantly share code, notes, and snippets.

@jvduf
Last active September 26, 2015 00:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvduf/1011476 to your computer and use it in GitHub Desktop.
Save jvduf/1011476 to your computer and use it in GitHub Desktop.
Misc Javascript Tricks
// The arguments variable in a function is not a real Array. So to be able to
// slice and dice it you need to convert OR handle it as an array:
// 1) Creating a new Array:
[].slice.call(arguments).doWhatEver // slower
// 2) Getting the Array Prototype:
Array.prototype.slice.call(arguments).doWhatEver // faster
// To test something is an Array or not:
var isArray = ({}).toString.call([]);
// But why not? ([]).toString
// Misc:
object.function.call(context) // calling proto with new context
// If you write the following, it will be a function declaration:
function() {}
// But if you write the following it will be the execution of a method:
!function() {};
// Or this, this will be an expression:
(function() {});
// Declaration can't be called, while expression can be :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment