查看: 1866|回复: 0

[JavaScript/JQuery] ES6 class_01 ..........

发表于 2018-3-4 17:45:33
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. </body>
  11. </html>
  12. <script type="text/javascript">
  13. {
  14. class Ponit{
  15. /*构造器的作用,初始化类定义的属性和方法*/
  16. constructor(x,y){
  17. this.x=x;
  18. this.y=y;
  19. }
  20. }
  21. /*逻辑值转换字符串*/
  22. Ponit.prototype.getVal=function(){
  23. var res=this.x+this.y;
  24. /*函数出口,把值外面处理*/
  25. return res;
  26. }
  27. var obj = new Ponit(5,8);
  28. console.log( obj.getVal() );
  29. }
  30. </script>
复制代码


回复

使用道具 举报