批改狀態(tài):合格
老師批語:
JavaScript創(chuàng)建對象的方式:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> // 構造方法創(chuàng)建JavaScript對象 function Stu(naem,sex,age){ this.name = name; this.sex = sex; this.age = age; } let stu = new Stu('小白','男',20); console.log(stu); // 函數創(chuàng)建對象 function cer(name,age){ var obj = new Object(); obj.name = name; obj.age = age; return obj; } let cer1 = cer('天達',22); console.log(cer1); // 字面量創(chuàng)建對象 let arr = {name:'天弘',fun:function(){return this.name}} console.log(arr.name); </script> </body> </html>
點擊 "運行實例" 按鈕查看在線實例
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號