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 hasStrictMode = (function() { | |
"use strict"; | |
return this === undefined; | |
}()); |
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
/** | |
* Person类(父类) | |
*/ | |
function Person(name, age) { | |
this.name = name; | |
this.age = age; | |
} | |
Person.prototype.getName = function() { | |
return this.name; |
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 walkTheDOM = function walk(node, func) { | |
func(node); | |
node = node.firstChild; | |
while(node) { | |
walk(node, func); | |
node = node.nextSibling; | |
} | |
} |
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 getElementsByAttribute(att, value) { | |
var results = []; | |
iterateDOM(document.body, function(node) { | |
var actual = node.nodeType === 1 && node.getAttribute(att); | |
if(typeof actual === 'string' && (actual === value || typeof value !== 'string')) { | |
results.push(node); | |
} | |
}); | |
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 factorial(i, a) { | |
a = a || 1; | |
if(i < 2) { | |
return a; | |
} | |
return factorial(i - 1, a * i); | |
} | |
factorial(4); // => 24 |
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 fibonacci = function() { | |
var memo = [0, 1]; | |
var fib = function(n) { | |
var result = memo[n]; | |
if(typeof result !== 'number') { | |
result = fib(n - 1) + fib(n - 2); | |
memo[n] = result; | |
} | |
return 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
var memoizer = function(memo, formula) { | |
var recur = function(n) { | |
var result = memo[n]; | |
if(typeof result !== 'number') { | |
result = formula(recur, n); | |
memo[n] = result; | |
} | |
return result; | |
}; | |
return recur; |
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
<canvas width="300" height="300" id="test"></canvas> | |
<script type="text/javascript"> | |
var canvas = document.getElementById('test'); | |
var ctx = canvas.getContext('2d'); | |
//绘制螺旋图案的函数 | |
function drawSpirograph(ctx,R,r,O){ | |
var x1 = R-O; | |
var y1 = 0; | |
var i = 1; |
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 ramdom(min, max) { | |
if (max == null) { | |
max = min; | |
min = 0; | |
} | |
return min + Math.floor(Math.random() * (max - min + 1)); | |
} |
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 generateRandomAlphaNum(len) { | |
var rdmString = ""; | |
for( ; rdmString.length < len; rdmString += Math.random().toString(36).substr(2)); | |
return rdmString.substr(0, len); | |
} |
OlderNewer