Last active
September 26, 2015 00:38
-
-
Save jvduf/1011476 to your computer and use it in GitHub Desktop.
Misc Javascript Tricks
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
// 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