constructor 的一点操作

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	</body>
	<script>
		function Person () {
			if( ... ) {
				return new this.constructor();
				return new Person();
			}
		}
		
		Person = 123;
		
		new Person();
		
		//构造函数在调用的时候,根据不同的参数创建不同的对象
		
		
		//有时候根据需要在构造函数内部还会调用构造函数
		//在这个情况下,不要使用构造函数的名字,而应该使用 this.constructor来表示构造函数
		
		function Person () {}
		Person.prototype = {
			constructor: Person
		}; 
		//拆解
		function Person () {}
		var o = {};
		o.constructor = Person; //属性中就存储着函数的地址
		
		Person.prototype = o;
		
		Person = 123;
	</script>
</html>

猜你喜欢

转载自blog.csdn.net/wusiye_123456/article/details/78688027