JavaScript杂谈(第六天)

js中可以使用Function创建函数

var func=new Function();

这个对象可以将字符串转换为函数

var func=new Function("console.write('hello world')");

func();

函数中有内置的arguments变量,根据这个变量可以获取到函数传递过来的所有参数;这就使我们可以使用可变参数列表的函数;

function test(){

  for(var i=0;i<arguments.length;i++){

    console.write(argument[i]);

  }

}

test(1,2,3,4);

instanceof 关键字的使用方法;判断构造函数是否存在于对象的原型链上;

function Person(){};

var p=new Person();

console.write(p instanceof Person);//true;

console.write(p instanceof Object);//true;

猜你喜欢

转载自www.cnblogs.com/ljs0322/p/8995881.html