Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created April 25, 2013 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Burgestrand/5460882 to your computer and use it in GitHub Desktop.
Save Burgestrand/5460882 to your computer and use it in GitHub Desktop.
Coffee script annotated output
var Kitten, Mooer, _ref,
__hasProp = {}.hasOwnProperty,
__extends = 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;
};
Mooer = (function ()
{
function Mooer()
{
// Constructor of Mooer. Runs when you call `new Mooer()`
}
return Mooer;
})();
Kitten = (function (_super)
{
// __extends(Kitten, Mooer); # =>
// Copy all class-level methods
// NOTE: Works for subclasses of Kitten too, since now all
// class-level methods will be the own property of Kitten.
for (var key in Mooer)
{
if (Mooer.hasOwnProperty(key))
Kitten[key] = Mooer[key];
}
// Clone of Mooer.prototype
function ctor()
{
// When you create functions, their prototype.constructor
// points back at them. This is a convention that should
// be held up because it’s nice to look normal.
this.constructor = Kitten;
}
ctor.prototype = Mooer.prototype;
// new ctor() == Object {} (__proto__ = Mooer.prototype)
Kitten.prototype = new ctor();
// We could do:
// Kitten.prototype = Mooer.prototype
// but that would cause any alterations to Kitten.prototype
// to be recorded on Mooer.prototype as well!
//
// Instead, we create a new object, whose’s prototype is set
// to Mooer (i.e. prototype chain lookup works). Essentially
// it’s like a clone of Mooer.prototype.
//
// Kitten.prototype = (new ctor() == Object {})
// Store reference to superclass; allows us to call superclass
// methods from instance methods.
Kitten.__super__ = Mooer.prototype;
// __extends ends.
function Kitten()
{
// Call the parent’s constructor, using the Kitten instance
// as `this`, passing along all arguments.
_ref = Kitten.__super__.constructor.apply(this, arguments);
return _ref;
}
return Kitten;
})(Mooer);
class Mooer
class Kitten extends Mooer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment