Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// Util
function placeholder(){}
function derive(Child, Parent){
placeholder.prototype = Parent.prototype
var proto = new placeholder()
for (var i = 2, l = arguments.length; i < l; i++){
var mixin = arguments[i]
for (var key in mixin) proto[key] = mixin[key]
}
return Child.prototype = proto
}
// Element
function Element(){
}
Element.prototype = {
render: function(){
}
}
// Transform
function Transform(){
}
Transform.prototype = {
rotate: function(){
}
}
// Shape
function Shape(){
this._()
}
Shape.prototype = derive(Element, Transform, {
_: Element,
_render: Element.prototype.render,
render: function(){
this._render()
},
draw: function(){
}
})
// Triangle
function Triangle(){
this.__()
}
Triangle.prototype = derive(Shape, {
__: Shape,
__draw: Shape.prototype.draw,
__render: Shape.prototype.render,
draw: function(){
this.__draw()
},
render: function(){
this.__render()
}
})

um, ewww?

I think I'd rather see something more explicit and specific.
Or at the very least a code comment explaining what the underscores are actually for.

Owner

sebmarkbage commented Jan 22, 2011

Updated to something more explicit.

steida commented Jan 22, 2011

I haven't any special prototyping style, because pure JS is actually real codding style in Google Closure ;) Pure JS with goog.inherits function is fine enough. http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml

steida commented Jan 22, 2011

In the other words, you eunuchized live prototype inheritance for sake of composed objects. If someone override base method later, children __________ references will never be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment