Created
August 10, 2013 08:09
-
-
Save sudodoki/6199556 to your computer and use it in GitHub Desktop.
Useful snippets I'll lose other way I've seen in David Walsh's post
http://tech.pro/tutorial/1453/7-javascript-basics-many-developers-aren-t-using-properly
This file contains hidden or 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
// Cloning Array | |
var clone = myArray.slice(0); // naive clone | |
// Merging 2 arrays | |
var mergeTo = [4,5,6], | |
var mergeFrom = [7,8,9]; | |
Array.prototype.push.apply(mergeTo, mergeFrom); | |
# Array::push.apply mergeTo, mergeFrom | |
mergeTo; // is: [4, 5, 6, 7, 8, 9] | |
// Check for truthy key in object | |
if("geolocation" in navigator) { | |
// Do some stuff | |
} | |
// 'if (navigator.geolocation)' case - while that works correctly, it isn't always efficient, as that method of object detection | |
// can initialize resources in the browser. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment