Blogger Information
Blog 21
fans 0
comment 0
visits 12420
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
类和 Json对象
中天行者
Original
550 people have browsed it
  1. //类
  2. class Person {
  3. constructor(name,age,sex) {
  4. this.name = name;
  5. this.age = age;
  6. this.sex = sex;
  7. }
  8. getName(){
  9. return this.name;
  10. }
  11. getAge(){
  12. return this.age;
  13. }
  14. }
  15. let p1 =new Person('zhang',20,'nan');
  16. console.log(p1.getAge());
  17. //继承父类
  18. class Student extends Person{
  19. //构造函数
  20. constructor(name,age,sex,school) {
  21. super(name,age,sex);//继承父类的属性
  22. this.school=school;
  23. }
  24. }
  25. let s1 =new Student('zhang1',20,'nan','文化小学');
  26. console.log(s1.school);//文化小学
  27. //Json对象
  28. console.log(typeof s1);//object
  29. //对象转JSON字符串
  30. let s1String =JSON.stringify(s1);
  31. console.log(typeof s1String );//string
  32. //JSON字符串转对象
  33. let s1Obj = JSON.parse(s1String);
  34. console.log(typeof s1Obj)//object
  35. //包含js
  36. // node 中 js 包含 用 var {解构} = require("./a")
  37. // 前端JavaScript 中 用 import {解构} from "./a.js"
  38. //a.js 中 需要暴露出内容 用export暴露
  39. //暴露出类
  40. export class Person{
  41. }
  42. //暴露出变量
  43. export let a=55;
  44. //暴露默认方法
  45. export default function(){
  46. //node接收 当前js 时
  47. let fun = require('./a');
  48. //fun();
  49. //JavaScript 接收时
  50. // import hh from "./a.js";
  51. // hh() 直接调用
  52. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post