Skip to content

Instantly share code, notes, and snippets.

View lylijincheng's full-sized avatar

lylijincheng lylijincheng

View GitHub Profile
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;
}
@lylijincheng
lylijincheng / _vimrc
Last active December 22, 2015 06:38
_vimrc for windows($VIM/_vimrc); vimrc for linux (/etc/vim/vimrc)
"========== MY SETUP START ==========
"设置不兼容
set nocompatible
"设置默认字体
set guifont=Consolas:h9:cANSI
"设置配色方案
colo torte
@lylijincheng
lylijincheng / defination.js
Last active December 21, 2015 13:49
modules exports.
// A|CMD Module
// Step A: ()()
// Step B: (function() {})(function(){})
// Rock and roll
(function(definition) {
// RequireJS
if (typeof define === 'function') {
define(definition);
} else {
definition();
@lylijincheng
lylijincheng / orientationchangeevent.js
Created August 19, 2013 07:07
orientationchange on iOS and Android.
function orientationchangeevent(fn, context) {
return function() {
var args;
if (context.orientationchangeeventTimeout) {
clearTimeout(context.orientationchangeeventTimeout);
}
args = [].slice.call(arguments);
@lylijincheng
lylijincheng / es6-new
Last active December 21, 2015 06:48
ES6 new
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
@lylijincheng
lylijincheng / es6-oo.js
Created August 19, 2013 03:54
ES5 oo sample.
// ES6 class
Class Vehicle {
constructor(color) {
this.color = color;
this.speed = 0;
}
drive() {
this.speed = 40;
@lylijincheng
lylijincheng / es5-oo.js
Created August 19, 2013 03:35
ES5 oo sample.
// constructor
function Vehicle(color) {
this.color = color;
this.speed = 0;
}
Vehicle.prototype.drive = function() {
this.speed = 40;
}
@lylijincheng
lylijincheng / vendor.js
Created August 9, 2013 10:45
Prefix vendor for JS.
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];
@lylijincheng
lylijincheng / prefixStyle.js
Created August 9, 2013 10:44
CSS style prefix.
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) {
@lylijincheng
lylijincheng / klass.js
Last active December 20, 2015 18:08
klass
// Klass
(function(exports) {
// shim
if (typeof Object.create !== "function") {
Object.create = function(o) {
function F() {}
F.prototype = o;
return new F;
};