123456789101112131415161718192021222324252627282930 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // 构造函数
- var arr = new Array(1,2,3,4);
- var str = new String('1234');
- function Person(userName,userAge){
- this.userName = userName;
- this.userAge = userAge;
- this.talk = function(){
- console.log(`大家好我叫${this.userName}今年${this.userAge}岁了`);
- }
- }
- var person1 = new Person('张三',18);
- console.log(person1.userName);
- console.log(person1.userAge);
- person1.talk();
- var person2 = new Person('李四',20);
- console.log(person2.userName);
- person2.talk();
- </script>
- </body>
- </html>
|