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
// reducer | |
function todosReducer(state, action) { | |
switch (action.type) { | |
case 'add': | |
return [...state, { | |
text: action.text, | |
completed: false | |
}]; | |
// ... other actions ... | |
default: |
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 getByteLen(normal_val) { | |
// Force string type | |
normal_val = String(normal_val); | |
var byteLen = 0; | |
for (var i = 0; i < normal_val.length; i++) { | |
var c = normal_val.charCodeAt(i); | |
byteLen += c < (1 << 7) ? 1 : | |
c < (1 << 11) ? 2 : | |
c < (1 << 16) ? 3 : |
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 deepClone(obj, hash = new Map()) { | |
if (Object(obj) !== obj) return obj; // primitives | |
if (hash.has(obj)) return hash.get(obj); // cyclic reference | |
var result = Array.isArray(obj) ? [] | |
: obj.constructor ? new obj.constructor() : {}; | |
hash.set(obj, result); | |
if (obj instanceof Map) | |
Array.from(obj, ([key, val]) => result.set(key, deepClone(val, hash)) ); | |
return Object.assign(result, ...Object.keys(obj).map ( | |
key => ({ [key]: deepClone(obj[key], hash) }) )); |
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
crypto.createHash('md5').update(text).digest('hex') |
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
https://github.com/ded/klass/blob/master/klass.js |
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
/** | |
* Hilo | |
* Copyright 2015 alibaba.com | |
* Licensed under the MIT License | |
*/ | |
/** | |
* @language=en | |
* Create Example Class: | |
* <pre> |
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
//Lets create a simple particle system in HTML5 canvas and JS | |
//Initializing the canvas | |
var canvas = document.getElementById("canvas"); | |
var ctx = canvas.getContext("2d"); | |
//Canvas dimensions | |
var W = 500; var H = 500; | |
//Lets create an array of particles |
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
//简易模板引擎实现 | |
//http://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line | |
//https://segmentfault.com/a/1190000005705169 | |
var TemplateEngine = function(html, options) { | |
var re = /<%([^%>]+)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0, match; | |
var add = function(line, js) { | |
js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : | |
(code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); | |
return add; | |
} |
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
// This function: | |
function foo() { | |
var x = 5; | |
var y = 6; | |
debugger; | |
return x + y; | |
} |
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
document.addEventListener('WeixinJSBridgeReady', function(){ | |
//如果执行到这块的代码,就说明是在微信内部浏览器内打开的. | |
alert('当前页面在微信内嵌浏览器中打开!'); | |
}); |
NewerOlder