标签:参数 span ring 一个 语句 cti log one string
function addOne(a) { return a + 1; }; function multiTwo (a) { return a*2; } function divThree (a) { return a/3; } function toString (a) { return a + ‘‘; } function split(a) { return a.split(‘‘); } function compose(divThree, multiTwo, addOne, toString, split) { // var func_list = [divThree, multiTwo, addOne, toString, split]; var func_list = new Array(); console.log(‘arguments‘, arguments); for (var arg_index in arguments) { var func = arguments[arg_index]; if (typeof func !== ‘function‘) { throw "参数:‘" + func + "‘不是函数"; // throw抛出异常,在throw语句后立即终止, 它后面的语句执行不到, } func_list.push(func); } return function(value) { func_list.map(function(func_item) { value = func_item(value); }); return value; } } console.log(compose(divThree, multiTwo, addOne, toString, split)(666)); // ["4", "4", "5"]
标签:参数 span ring 一个 语句 cti log one string
原文地址:https://www.cnblogs.com/lvsk/p/12722499.html