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
/* General Statement: To convert values to a particular datatype use type coercsion instead of explicit conversion. */ | |
/* To Number */ | |
var val = "123"; | |
// 1. using Exclusing Type conversion. | |
console.log(Number(val)); | |
// 2. using Type Coercion (unary plus operator) | |
console.log(+val); | |
// among these methods the Type Coercion is fast. (http://jsperf.com/number-vs-unary-plus) |
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
console.log("1"); | |
(function level1(){ | |
console.log("2"); | |
setTimeout(function async1(){ | |
console.log("3"); | |
},0); | |
(function level2(){ | |
console.log("4"); | |
setTimeout(function async2(){ | |
console.log("5"); |
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
;(function($){ | |
$.importProp = function($this, $src, subset) { | |
if(subset){ | |
$.each(subset, function(i, key){ | |
$this[key] = $src[key]; | |
}); | |
} else { | |
$.each($src, function(key, e){ | |
$this[key] = $src[key]; | |
}); |
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
Object.defineProperty(Object.prototype, 'deepVal', { | |
enumerable: false, | |
configurable: false, | |
writable: false, | |
value: function (string){ | |
var props = string.split("."), | |
val = {}; | |
for(var key in this){ | |
val[key] = this[key]; | |
} |
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
function getClass(obj) { | |
if (typeof obj === "undefined") | |
return "undefined"; | |
if (obj === null) | |
return "null"; | |
return Object.prototype.toString.call(obj) | |
.match(/^\[object\s(.*)\]$/)[1]; | |
} | |
getClass("") === "String"; |
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
/* | |
instead of declaring global variables. | |
var counter = 0; | |
$(document).on("click", function(){ | |
console.log(counter); | |
counter++; | |
}); | |
*/ | |
$(document).on("click", function handler(){ |
NewerOlder