Private methods and Inheritance

0 views
Skip to first unread message

Matt Foster

unread,
May 12, 2008, 1:15:25 PM5/12/08
to Ruby on Rails: Spinoffs
Hey Everyone,


I found Kangax's observable class and the function closure used
to create the instance and fell in love with the idea of easily
created private methods. I've whipped up an article exploring this
idea in much more detail. Feel free to check it out here,
http://positionabsolute.net/blog/2008/04/prototype-class-inheritance.php


--
Matt Foster
Ajax Engineer
Nth Penguin, LLC
http://www.nthpenguin.com

kangax

unread,
May 12, 2008, 8:43:07 PM5/12/08
to Ruby on Rails: Spinoffs
Matt, using closures to simulate "private" properties/methods has
actually been around for quite some time : ) (one of the most famous
examples is probably Crockford's "module" pattern)
I actually found such technique almost essential when aiming for high-
performance appls. Not only it lets you "hide" certain logic, but also
allows to instantiate and cache most of the things before function is
ever run. As an example, take a look at an Object.forIn
implementation, where most of the "things" that actual method needs
are stored in a closure: http://github.com/kangax/protolicious/tree/master/object.for_in.js

Best,
kangax

On May 12, 1:15 pm, Matt Foster <mattfoste...@gmail.com> wrote:
> Hey Everyone,
>
> I found Kangax's observable class and the function closure used
> to create the instance and fell in love with the idea of easily
> created private methods. I've whipped up an article exploring this
> idea in much more detail. Feel free to check it out here,http://positionabsolute.net/blog/2008/04/prototype-class-inheritance.php
Reply all
Reply to author
Forward
0 new messages