(1)知識點
- (1.1)定義函數(shù)的第二種方法 var 函數(shù)名 = function (參數(shù)1,參數(shù)2,...){代碼片段;return;}
- (1.2)在函數(shù)內,為沒有聲明過的變量賦值,變量會被自動創(chuàng)建在全局
- (1.3)BOM是browser object model的縮寫,簡稱瀏覽器對象模型
BOM可以參考:
http://www.dreamdu.com/javascript/what_is_bom/
document.write("www.dreamdu.com");//因為document屬于瀏覽器對象
document.getElementById("demo");//調用document瀏覽器對象的方法
- (1.4)不屬于任何對象的叫函數(shù),屬于特定對象的函數(shù)叫方法
(2)細化
(2.1)
(3)實踐
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>函數(shù)(二)</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
init();
function init() {
// 1.參數(shù)個數(shù)不足
m1(1);
// 2.參數(shù)相等
m1(1, 2, 3);
// 3.參數(shù)個數(shù)超過定義
m1(1, 2, 3, 4, 5);
}
function m1(a, b, c) {
console.log("a:" + a);
console.log("b:" + b);
console.log("c:" + c);
//d這個變量就是全局變量
d = 4;
}
//函數(shù)
function Person(name, age) {
this.name = name;
this.age = age;
//方法
this.say = function () {
console.log(this.name + " say hello");
}
}
</script>
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。