Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html id="home" lang="en">
- <head>
- <meta charset=utf-8 />
- <script type="text/javascript">
- Function.prototype.method = function(name, func) {
- this.prototype[name] = func;
- return this;
- };
- Object.prototype.create = function(prototype) {
- var func = function() {};
- func.prototype = prototype;
- return func;
- };
- Object.method('parent', function(name) {
- var self = this;
- var method = self[name];
- return function() {
- return method.apply(self, arguments);
- };
- });
- </script>
- </head>
- <body>
- <script type="text/javascript">
- var ClassA = function() {
- var self = {};
- self.object_method = function() {
- return "ClassA";
- };
- return self;
- };
- var ClassB = function() {
- var self = ClassA();
- var parent_object_method = self.parent('object_method');
- self.object_method = function() {
- return parent_object_method() + "ClassB";
- };
- return self;
- };
- var obj = ClassB();
- alert(obj.object_method());
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment