为什么都是222
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
</head>
<body>
<p id="page">
<p>
<a href="/signup/" onclick="app.requireLogin();return false;">注册</a>
<a href="#" onclick="app.requireLogin('', {to: 'login'});return false;">登录</a>
</p>
</p>
<script>
var app = {
requireLogin : function(a, b) {
console.log(b.to + "----");
if(b.to == 'login') {
$('#page').append('<h1>1111111</h1>');
}
},
requireLogin : function() {
console.log('reg');
$('#page').append('<h1>2222</h1>');
}
};
</script>
</body>
</html>
阿神2017-04-10 14:48:51
其实这样就类似于:
var a = 100;
var a = 200;
最终得到的就是200。
但是需要说明一下,在严格模式下:
{
a: 100,
a: 200
}
会报错。严格模式不允许对象属性同名。
非严格模式下,对象有同名属性时,后者会无条件覆盖前者。