Skip to content

Instantly share code, notes, and snippets.

@sjbarag
Created December 9, 2019 19:57
Show Gist options
  • Save sjbarag/f364bf64a88e928d03a4b51c89b80071 to your computer and use it in GitHub Desktop.
Save sjbarag/f364bf64a88e928d03a4b51c89b80071 to your computer and use it in GitHub Desktop.
var Foo, f,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Foo = (function(superClass) {
extend(Foo, superClass);
function Foo() {
this.sayHello = bind(this.sayHello, this);
return Foo.__super__.constructor.apply(this, arguments);
}
Foo.prototype.sayHello = function(name) {
return console.log("Hello, " + name + "!");
};
return Foo;
})(Bar);
f = new Foo();
setImmediate(function() {
return f.sayHello("Dave");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment