class.js 487 B

12345678910111213141516171819202122232425
  1. /*
  2. * @Description: js类测试
  3. * @Autor: kindring
  4. * @Date: 2021-09-06 16:18:22
  5. * @LastEditors: kindring
  6. * @LastEditTime: 2021-09-06 16:22:29
  7. * @LastDescript:
  8. */
  9. class Fn {
  10. constructor(id, name) {
  11. this.id = id
  12. this.name = name
  13. }
  14. say(talk) {
  15. console.log(`${this.name}:${talk}`);
  16. this.onSay({ date: new Date(), talk })
  17. }
  18. static onSay() {}
  19. }
  20. let f = new Fn(1, '张三')
  21. f.onSay = function(e) {
  22. console.log(e)
  23. }
  24. f.say('你好')