返回列表

Javascript区分function是函数/方法还是对象构造器

默认分类 2011-01-16 19:31:35

Javascript中可以使用this instanceof arguments.callee来区分function是函数/方法还是对象构造器

function fun01(){
    if(!(this instanceof arguments.callee)) 
        {throw "Error: missing 'new' operator.";}
    this.name = "peter";
}
var aa = new fun01();
alert(aa.name);
var bb = fun01();
//alert(bb.name);