无法运行
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var Student={
name:"xiaoming",
age:18,
chinese_score:150,
math_score:150,
avg.function(){
return (this.chinese_score+this.math_score)/2;
}
}
console.log(Student.name);
console.log(Student.avg());
</script>
</body>
Uncaught SyntaxError: Unexpected token '.'
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
正常运行
avg:function()
前边的定义都是名称:内容,怎么到这里变成点了
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var Student={
name:"xiaoming",
age:18,
chinese_score:150,
math_score:150,
}
function avg(){
return (this.chinese_score+this.math_score)/2;
}
console.log(Student.name);
console.log(avg());
</script>
</body>