Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- // 'use strict';
- // ^ would throw error because of `arguments.callee.caller`.
- var ModuleCore = function() {};
- ModuleCore.prototype.html = function() {
- console.log(':: html');
- };
- ModuleCore.extend = function (settings, Parent) {
- var parent;
- if (typeof Parent !== 'undefined') {
- parent = new Parent();
- } else {
- parent = new ModuleCore();
- }
- var M = function() {};
- M.prototype = Object.assign(parent, settings);
- M.extend = function(settings) {
- settings.super = settings.super || function() {
- var caller = arguments.callee.caller;
- parent[caller.name].apply(this, caller.arguments);
- };
- return ModuleCore.extend.call(null, settings, M);
- };
- return M;
- };
- var m = ModuleCore.extend({
- render: function() {
- this.html();
- console.log('m1 render!', arguments);
- }
- });
- var m2 = m.extend({
- render: function() {
- // `this.super()` will automaticaly 'guess'
- // function name ('render') as well as `arguments` value.
- this.super();
- console.log('m2 render!');
- }
- });
- var foo = new m2();
- console.log(foo.render(1));
- // :: html
- // m1 render! [1]
- // m2 render!
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement