[英]How do I combine 2 prewritten Javascript functions
我想將一個功能嵌套到另一個功能中嗎?
這是您要的嗎?
function add1(x){
return x + 1;
}
function mult2(x){
return x * 2;
}
function add1ThenMult2(x){
return mult2(add1(x));
}
add1ThenMult2(10); // --> 22
或者隱藏2個功能...
var add1ThenMult2 = (function(){
function add1(x){
return x + 1;
}
function mult2(x){
return x * 2;
}
function add1ThenMult2(x){
return mult2(add1(x));
}
return add1ThenMult2;
}());
add1ThenMult2(10); // --> 22
您可能會考慮使用jquery-aop在給定函數周圍或之前添加建議。
或原型的wrap
函數 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.