Guest User

Untitled

a guest
Jul 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html id="home" lang="en">
  3.     <head>
  4.         <meta charset=utf-8 />
  5.         <script type="text/javascript">
  6.             Function.prototype.method = function(name, func) {
  7.                 this.prototype[name] = func;
  8.                 return this;
  9.             };
  10.            
  11.             Object.prototype.create = function(prototype) {
  12.                 var func = function() {};
  13.                 func.prototype = prototype;
  14.                 return func;
  15.             };
  16.            
  17.             Object.method('parent', function(name) {
  18.                 var self = this;
  19.                 var method = self[name];
  20.                 return function() {
  21.                     return method.apply(self, arguments);
  22.                 };
  23.             });
  24.         </script>
  25.     </head>
  26.     <body>
  27.         <script type="text/javascript">
  28.             var ClassA = function() {
  29.                 var self = {};
  30.                
  31.                 self.object_method = function() {
  32.                     return "ClassA";
  33.                 };
  34.                
  35.                 return self;
  36.             };
  37.            
  38.             var ClassB = function() {
  39.                 var self = ClassA();
  40.                
  41.                 var parent_object_method = self.parent('object_method');
  42.                 self.object_method = function() {
  43.                     return parent_object_method() + "ClassB";
  44.                 };
  45.                 return self;
  46.             };
  47.            
  48.             var obj = ClassB();
  49.            
  50.             alert(obj.object_method());
  51.         </script>
  52.     </body>
  53. </html>
Add Comment
Please, Sign In to add comment