日期:2014-05-16 浏览次数:20509 次
function Parent(username){
		this.username = username;
		this.sayHello = function(){
			alert("hello,"+this.username);
		}
	}
	function Child(username,password){
               //三行重要代码
		this.method = Parent;
		this.method(username);
		delete this.method;
		this.password = password;
		this.sayWorld = function(){
			alert("world,"+this.password);
		}
	}
	var parent = new Parent("wlh");
	var child = new Child("wlh_child","111111");
	parent.sayHello();
	child.sayHello();
	child.sayWorld();
function test(str,str2){
		alert(this.name + "," +str + "," +str2);
}
var object = new Object();
object.name = "wlh";
//相当于调用了test函数
test.call(object,"wlhs");//将object赋给了this
function Parent(username){  
        this.username = username;  
        this.sayHello = function(){  
            alert("hello,"+this.username);  
        }  
    }  
    function Child(username,password){  
		Parent.call(this,username);
		this.password = password;
		this.sayWorld = function(){  
            alert("world,"+this.password);  
        }  
	}
	var parent = new Parent("wlh");  
    var child = new Child("wlh_child","111111");  
    parent.sayHello();  
  
    child.sayHello();  
    child.sayWorld();  
function Parent(username){  
        this.username = username;  
        this.sayHello = function(){  
            alert("hello,"+this.username);  
        }  
    }  
    function Child(username,password){  
		Parent.apply(this,new Array(username));
		this.password = password;
		this.sayWorld = function(){  
            alert("world,"+this.password);  
        }  
	}
	var parent = new Parent("wlh");  
    var child = new Child("wlh_child","111111");  
    parent.sayHello();  
  
    child.sayHello();  
    child.sayWorld();  
function Parent(){
	}
	Parent.prototype.username = "wlh";
	Parent.prototype.getUsername = function(){
		alert(this.username);
	}
	function Child(){
	}
	Child.prototype = new Parent();
	Child.prototype.password = "111111";
	Child.prototype.getPassword = function(){
		alert(this.password);
	}
	var child = new Child();
	child.getUsername();
	child.getPassword();
	function Parent(username){
		this.username = username;
	}
	Parent.prototype.getUsername = function(){
		alert(this.username);
	}
	function Child(username,password){
		Parent.call(this,username);
		this.password = password;
	}
	Child.prototype = new Parent();
	Child.prototype.getPassword = function(){
		alert(this.password);
	}
	var child = new Child("wlh","111111");
	child.getUsername();
	child.getPassword();