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
/* | |
instead of declaring global variables. | |
var counter = 0; | |
$(document).on("click", function(){ | |
console.log(counter); | |
counter++; | |
}); | |
*/ | |
$(document).on("click", function handler(){ |
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
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 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 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 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 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
// just typepof myVar == 'string' fails when my var is declared => var myVar = new String("value"); | |
if (typeof myVar == 'string' || myVar instanceof String){ | |
// it's a string | |
} | |
// just typepof myVar == 'string' fails when my var is declared => var myVar = new String("value"); | |
if (typeof myVar == 'number' || myVar instanceof Number){ | |
// it's a string | |
} |
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
(function($) { | |
$.extend({ | |
throttle : function(fn, timeout, ctx) { | |
var timer, args, needInvoke; | |
return function() { | |
args = arguments; | |
needInvoke = true; | |
ctx = ctx || this; | |
if(!timer) { | |
(function() { |
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
/** crop vertical portions **/ | |
.outer-wrap{ | |
position:relative; | |
width:100px; | |
height:100px; /* @OH */ | |
background:#ccc; | |
overflow:hidden; | |
} | |
.inner-wrap{ |
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
/* Solution 1 (best) */ | |
.wrap{ | |
position:relative; | |
} | |
img{ | |
position:abosulute; | |
top:0; | |
right:0; | |
bottom:0; | |
left:0; |
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
a{ | |
line-height:0; | |
/*font-size:0; will not work only line-height*/ | |
} |
OlderNewer