function addLoadEvent(fn) {
var oldEvent = window.onload;
if(typeof window.onload != 'function') {
window.onload = fn;
}else {
window.onload = function() {
oldEvent();
fn();
};
}
}
function fn1() {
console.log('onloadFunc 1');
}
function fn2() {
console.log('onloadFunc 2');
}
function fn3() {
console.log('onloadFunc 3');
}
addLoadEvent(fn1);
addLoadEvent(fn2);
addLoadEvent(fn3);
Function.prototype.before = function(beforfunc) {
var self = this;
var outerArgs = Array.prototype.slice.call(arguments, 1);
return function() {
var innerArgs = Array.prototype.slice.call(arguments);
beforfunc.apply(this, innerArgs);
self.apply(this, outerArgs);
};
};
Function.prototype.after = function(afterfunc) {
var self = this;
var outerArgs = Array.prototype.slice.call(arguments, 1);
return function() {
var innerArgs = Array.prototype.slice.call(arguments);
self.apply(this, outerArgs);
afterfunc.apply(this, innerArgs);
};
};
var func = function(name){
console.log('I am ' + name);
};
var beforefunc = function(age){
console.log('I am ' + age + ' years old');
};
var afterfunc = function(gender){
console.log('I am a ' + gender);
};
var beforeFunc = func.before(beforefunc, 'Andy');
var afterFunc = func.after(afterfunc, 'Andy');
beforeFunc('12');
afterFunc('boy');
I am 12 years old I am Andy I am Andy I am a boy
function log(func){
return function(...args){
const start = Date.now();
let result = func(...args);
const used = Date.now() - start;
console.log(`call ${func.name} (${args}) used ${used} ms.`);
return result;
};
}
function calculate(times){
let sum = 0;
let i = 1;
while(i < times){
sum += i;
i++;
}
return sum;
}
runCalculate = log(calculate);
let result = runCalculate(100000);
console.log(result);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有