跳转到内容

编程的科学/ Sway 演示文稿/ 对象/ 类以及对象组件 2

来自维基教科书,一个开放世界的开放书籍

类以及对象组件,续

尝试一下...

   var z =
   {
   var z_shared = { var count = 0; this; };
   
   function z()
       {
       var shared = z_shared;
       var count = 0;
       shared . count += 1;
       count += 1;
       this;
       }
   };
   
   function x()
       {
       extends(z());
       }

测试...

   inspect(x() . shared . count);
   inspect(x() . count);
   inspect(x() . shared . count);

输出如预期

   x() . shared . count is 1
   x() . count is 1
   x() . shared . count is 3

串联 之美...

华夏公益教科书