JS高級 —— 普通函數、構造函數、對象方法的調用


 1 <!DOCTYPE html>  2 <html>  3 <head>  4 <meta charset="utf-8">  5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  6 <title>函數的調用方式</title>  7 </head>  8 <script>  9 // 普通函數---直接調用 10 function f1() { 11  console.log("putonghanshu"); 12  } 13  f1(); 14 // 構造函數---通過new來調用  15 function F1(){ 16  console.log("gouzaohanshu") 17  } 18 var f = new F1(); 19 20 // 對象的方法---對象.方法(); 21 function Person(){ 22 this.play = function(){ 23  console.log("Person is playing") 24  }; 25  } 26 var per = new Person(); 27  per.play(); 28 29 </script> 30 <body> 31 </body> 32 </html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM