Advertisement
Shirai

OOP in JS

Apr 11th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.70 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <script>
  4.         var Meo = function(trongluong){
  5.             var self = this;
  6.             self.trongLuong = trongluong;
  7.             self.batChuot = function(chuot){
  8.                 self.trongLuong += chuot.trongLuong;
  9.                 console.log(self.trongLuong);
  10.             }
  11.         }
  12.         var Chuot = function(trongluong){
  13.             var self = this;
  14.             this.trongLuong = trongluong;
  15.         }
  16.         var meo1 = new Meo(2000);
  17.         var chuot1 = new Chuot(200);
  18.         var chuot2 = new Chuot(300);
  19.         var chuot3 = new Chuot(400);
  20.         meo1.batChuot(chuot1);
  21.         meo1.batChuot(chuot2);
  22.         meo1.batChuot(chuot3);
  23.     </script>
  24. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement