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 arraySum(i) { | |
// i will be an array, containing integers, strings and/or arrays like itself. | |
// Sum all the integers you find, anywhere in the nest of arrays. | |
var index, entry, ret = 0, len = i.length; | |
for(index = 0; index < len; index += 1){ | |
entry = i[index]; | |
ret += entry instanceof Array ? arraySum(entry)) : entry; | |
} |
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
"========== MY SETUP START ========== | |
"设置不兼容 | |
set nocompatible | |
"设置默认字体 | |
set guifont=Consolas:h9:cANSI | |
"设置配色方案 | |
colo torte |
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|CMD Module | |
// Step A: ()() | |
// Step B: (function() {})(function(){}) | |
// Rock and roll | |
(function(definition) { | |
// RequireJS | |
if (typeof define === 'function') { | |
define(definition); | |
} else { | |
definition(); |
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 orientationchangeevent(fn, context) { | |
return function() { | |
var args; | |
if (context.orientationchangeeventTimeout) { | |
clearTimeout(context.orientationchangeeventTimeout); | |
} | |
args = [].slice.call(arguments); |
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
ES6 points | |
http://www.sencha.com/blog/toward-modern-web-apps-with-ecmascript-6/ | |
Default parameter value | |
Lexical block scope | |
Concise method definition | |
Arrow function | |
Spread operator | |
Rest parameters | |
Array comprehension |
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
// ES6 class | |
Class Vehicle { | |
constructor(color) { | |
this.color = color; | |
this.speed = 0; | |
} | |
drive() { | |
this.speed = 40; |
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
// constructor | |
function Vehicle(color) { | |
this.color = color; | |
this.speed = 0; | |
} | |
Vehicle.prototype.drive = function() { | |
this.speed = 40; | |
} |
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 vendor = function() { | |
var vendors, i, len, style; | |
vendors = ['', 'webkit', 'ms', 'Moz', 'O']; | |
style = document.createElement('div').style; | |
len = vendors.length; | |
for (i = 0; i < len; i += 1) { | |
if ((vendors[i] + 'Transform') in style) { | |
return vendors[i]; |
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 prefixStyle = function(style) { | |
var i, len, vendor, vendors, blank, camel; | |
vendors = ['', 'webkit', 'ms', 'Moz', 'O']; | |
blank = document.createElement('div').style; | |
camel = style.charAt(0).toUpperCase() + style.slice(1); | |
for (i = 0, len = vendors.length; i < len; 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
// Klass | |
(function(exports) { | |
// shim | |
if (typeof Object.create !== "function") { | |
Object.create = function(o) { | |
function F() {} | |
F.prototype = o; | |
return new F; | |
}; |