返回列表

ebay

默认分类 2013-02-28 12:46:31

Q1:

    function F(){
        var name = 'ffff';
        setName = function(n){
            name = n;
        };
        this.setName = function(d){setName(d);};
        this.getName = function(){return name;};
    }

    var a = new F();
    var b = new F();
    var c = new F();
    a.setName('dddd');
    alert(a.getName());
    alert(b.getName());
    alert(c.getName());

Q2:

    function Person(){};
    var tom = new Person();
    Person.prototype.name = 'user';
    alert(tom.name);
    Person.prototype = {age:12};
    alert(tom.age);
    alert(tom instanceof Person);

Q3:

    function F(){
        alert(this);
    }
    F.call(null);

Q4:

    var a=function(){return 'bb'};   
    function a() {
        return 'aa';
    }  
    alert(a()); 

Q5:

    function doit(){
        alert(a);
        if (4>5) {
            var a = 3;
        }
    }