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 _name() { | |
//... | |
} | |
// 函数表达式 | |
var _name = 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
// 自执行函数 | |
;(function() { | |
//... | |
})(); | |
// dom 绑定. | |
document.onclick = 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
// partial | |
;(function() { | |
var BASE_FONT_SIZE = 100; | |
var zoom = partial(function( a, b ) { | |
return a + b; | |
}, BASE_FONT_SIZE ); | |
var result = zoom( -30 ); // 70 | |
var result2 = zoom( 50 ); // 150 |
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 type(s) { | |
return Object.prototype.toString.call(s).slice(8,-1).toLowerCase(); | |
} | |
console.assert( type( null ) == 'null', 'null' ); | |
console.assert( type( undefined ) == 'undefined', 'undefined' ); | |
console.assert( type( [] ) == 'array', '[]' ); | |
console.assert( type( {} ) == 'object', 'object' ); | |
console.assert( type( false ) == 'boolean', 'false' ); | |
console.assert( type( 1.2 ) == 'number', '1.2' ); |
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
var result = 80; | |
var MAX_VALUE = 50; | |
var MIN_VALUE = 0; | |
// result 值不能小于 0 | |
result = Math.max.call( Math, MIN_VALUE, result ); | |
result = Math.min.apply( Math, [ MAX_VALUE, result ] ); | |
console.log( result ); |
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
/* | |
@return {object} | |
{ | |
on: 开权限 | |
off: 取消权限 | |
done: 有权限时, 执行操作 | |
} | |
*/ | |
function create( func, check, time ) { | |
var flag = false; |
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 removeDomByClass( classname ) { | |
var boxes = document.getElementsByClassName( classname ); | |
for ( var i = 0, l = boxes.length; i < l; i++ ) { | |
var box = boxes[0]; | |
if ( box && box.parentNode ) { | |
box.parentNode.removeChild( box ); | |
} | |
} | |
} |
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
var type = function(s) { | |
return Object.prototype.toString.call(s).slice(8,-1).toLowerCase(); | |
}; | |
var log = function() { | |
var color = 'background: #000;color: yellow;padding: 0 3px'; | |
var string = '%c';//'%c'; | |
for ( var i = 0, l = arguments.length; i < l; i++ ) { | |
var t = type(arguments[i]); | |
switch(t) { |
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
var f; | |
f = function ( n ) { | |
if ( n === 0 ) return 0; | |
else | |
return n + f(n-1); | |
}; | |
var a = f(3); | |
console.log( 'a: ', a ); |
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
var a = [ 1, 2, 3 ]; | |
function change( a, i, j) { | |
var t = a[i]; | |
a[i] = a[j]; | |
a[j] = t; | |
} | |
function permgen( a, n ) { | |
n = n == null ? a.length : n; |
OlderNewer