Array.prototype.slice.call(arguments)一般用于插件开发当中,请看下边demo
var ceshi=function(){ this.Init.apply(this,arguments); } ceshi.prototype={ Init:function(){ var args=Array.prototype.slice.call(arguments,0); var config=args[0]; console.log(config);//控制台输出了x的对象了! //可以看到这里已经把外部的构造函数内容传入到config下了,接下来就可以针对外部的参数去编写内部功能模块的代码了! } } //调用方法: var x=new ceshi({ a:"1", b:'2', c:['1','2','3'], d:function(e){ //一般是用于插件的回调函数 } });