javascript 对象中属性的查找。hasOwnProperty 和 ‘name’ in object;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<script>
	function abc(name,age,sex){
		this.name = name;
		this.age = age;
		this.sex = sex;
	}
	abc.prototype.nationality = '中国';
	var abca = new abc('wulei',30,'nv');
	
	console.log(abca);
	abca.hasOwnProperty('name');
	
	alert('name' in abca);
	
</script>

	
</body>
</html>

发表评论

邮箱地址不会被公开。