现在的位置: 首页 > 综合 > 正文

What is the usage of the Javascript method call and apply(what is the new and object.create difference.)

2012年09月19日 ⁄ 综合 ⁄ 共 568字 ⁄ 字号 评论关闭

firstly please review a code sample below .

<html>
	<head>
		<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
		<script  type="text/javascript">
			/**/
			$(function(){
				var baseObj=function(){
				this.firstname="joe";
				this.lastname="wang";
			
				};
				
				var childObj=function(){
					this.firstname="wq";
				};
				
				var b= new baseObj();
				var c = new childObj();
				baseObj.call(c);
				alert(c.firstname);
			
			
			});
			
		
		</script>
	</head>
	<body>
	
	</body>
</html>

 

the output is "joe" instead of the "wq".

so, found the mystery the call ?

 see also:

http://stackoverflow.com/questions/4166616/understanding-the-difference-between-object-create-and-new-somefunction-in-j

 

 

抱歉!评论已关闭.