js prototype 과 call

1098 단어 js






nb

	function nb(){
		function dog(){
			this.say=function(){
				console.log("my name is "+this.name);
			}
		}
		function dog1(){
			this.name="hqc";
		}
		function dog2(){
			this.name="lj";
		}
		dog1.prototype = new dog();//  
		var hqc = new dog1();//       
		hqc.say();
		//dog2.prototype = new dog();
		var lj = new dog2();
		hqc.say.call(lj);
	}
	function nb2(){
		function dog(){
			this.name="hqc";
			this.say=function(){
				console.log("my name is "+this.name);
			}
		}
		function dog2(){
			this.name="lj";
		}
		var hqc = new dog();
		hqc.say();
		var lj = new dog2();
		hqc.say.call(lj);
	}






좋은 웹페이지 즐겨찾기