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
grunt.registerMultiTask('delete', function(when, task) { | |
var path = require( 'path' ), fs = require( 'fs' ); | |
var queue = function( list, fn, callback, index, ret ) { | |
"use strict"; | |
index = index || 0; | |
ret = ret || []; | |
var next = function ( value, stop, returnCurrentValue ) { | |
ret[ ret.length ] = value; | |
if ( stop ) { | |
return callback.apply( null, returnCurrentValue ? [value] : ret ); |
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 f1() { | |
var count = 1; | |
var last = Date.now(); | |
var ret = []; | |
setTimeout(function() { | |
ret.push( Date.now() - last ); | |
var i = 0, c; | |
while ( i++ < 100000 ) { | |
c = document.getElementsByTagName( '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 = { | |
x: 'x', | |
y: 'y', | |
z: ['x','y','z'] | |
}; | |
a.z1 = a.z; // 共享数据 | |
a.a1 = a; // 环 | |
console.log( 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 = Math.random() * 6 + 2; | |
var b = typeof a === 'number' && a > 5 && a - 5 || 'redky'; | |
console.log( a, b ); |
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; |
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 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
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
/* | |
@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
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 ); |