<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> </body> </html> <script> var type={}; for(var i=0,t;t=['String','Array','Object'][i++];){ (function(t){ type['is'+t] = function(obj){ return Object.prototype.toString.call(obj) == '[object '+ t+ ']' } })(t) } console.log(type.isArray([])); // 函数数组,若是不想经过索引来调用函数,能够建立一个对象,如上所示代码. var fun_arr=[]; for(var i=0;i<5;i++){ (function(i){ fun_arr.push(function(args){ console.log(args); }); })(i) } console.log(fun_arr); // call fun_arr[0]([1,2,3]); fun_arr[1]("welcom javascrip"); // 这样作的目的是能够将一些类型很接近的函数封装在一个对象中, </script>