This file contains hidden or 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 mix(...mixins) { | |
class Mix {} | |
for (let mixin of mixins) { | |
copyProperties(Mix, mixin); // 拷贝实例属性 | |
copyProperties(Mix.prototype, mixin.prototype); // 拷贝原型属性 | |
} | |
return Mix; | |
} |
This file contains hidden or 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
// Array Remove - By John Resig (MIT Licensed) | |
Array.prototype.remove = function(from, to) { | |
var rest = this.slice((to || from) + 1 || this.length); | |
this.length = from < 0 ? this.length + from : from; | |
return this.push.apply(this, rest); | |
}; | |
// 移除数组中的第二项 | |
// array.remove(1); |
This file contains hidden or 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 dfGetter=function(target, property, receiver){ | |
return target[property]; | |
}; | |
var dfSetter=function(target, property, value, receiver){ | |
return target[property]=value; | |
}; | |
const _Proxy = function(target, handler){ | |
var me=this; | |
if(!handler.get){ |
This file contains hidden or 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 co(gen) { | |
var ctx = this; | |
return new Promise(function(resolve, reject) { | |
if (typeof gen === 'function') gen = gen.call(ctx); | |
if (!gen || typeof gen.next !== 'function') return resolve(gen); | |
onFulfilled(); | |
function onFulfilled(res) { | |
var ret; |
This file contains hidden or 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
// node-Thunkify | |
function thunkify(fn) { | |
return function() { | |
var args = new Array(arguments.length); | |
var ctx = this; | |
for (var i = 0; i < args.length; ++i) { | |
args[i] = arguments[i]; | |
} |
This file contains hidden or 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
//除法函数,用来得到精确的除法结果 | |
//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 | |
//调用:accDiv(arg1,arg2) | |
//返回值:arg1除以arg2的精确结果 | |
function accDiv(arg1, arg2) { | |
var t1 = 0, | |
t2 = 0, | |
r1, r2; | |
try { | |
t1 = arg1.toString().split(".")[1].length |
This file contains hidden or 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
/** | |
* js AOP | |
* 实现AOP,提供before和after通知 | |
* @author Leo | |
*/ | |
!function(global, undefined){ | |
var aspect = function(){}; | |
//aop核心实现 |
This file contains hidden or 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
NewerOlder