Instantly share code, notes, and snippets.

Embed
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()
}
})
@subtleGradient

This comment has been minimized.

Show comment
Hide comment
@subtleGradient

subtleGradient commented Jan 21, 2011

um, ewww?

@subtleGradient

This comment has been minimized.

Show comment
Hide comment
@subtleGradient

subtleGradient Jan 21, 2011

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.

subtleGradient commented Jan 21, 2011

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.

@sebmarkbage

This comment has been minimized.

Show comment
Hide comment
@sebmarkbage

sebmarkbage Jan 22, 2011

Updated to something more explicit.

Owner

sebmarkbage commented Jan 22, 2011

Updated to something more explicit.

@steida

This comment has been minimized.

Show comment
Hide comment
@steida

steida 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

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

This comment has been minimized.

Show comment
Hide comment
@steida

steida 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.

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.

@steida

This comment has been minimized.

Show comment
Hide comment
@steida

steida commented Jan 25, 2011

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