On Wed, Oct 26, 2011 at 11:21 AM, ydaniv <maggotf...@gmail.com> wrote:

> @Jake:
> Yes, I understood exactly why you wanted it configurable, it makes
> good sense.
>
> As for the reason we need something more then just
> Object.getPrototypeOf():
> I wished it could get down to that and we could simply use this, but,
> I'll give you a very common use case where this fails:
>
> var instance = {
>  __proto__: {
>    method: function () { alert('a'); },
>    __proto__: {
>      method: function () { alert('super a'); }
>    }
>  }
> }
>
> "instance" is an instance of some class that has a method "method" and
> it inherits another class that has a method by the same name.
> If you call Object.getPrototypeOf() on "instance" and ask for the
> method "method" you'll get the same method. Bummer!
> Say you had this method call its super inside it:
>
> method: function () { alert('a'); return
> Object.getPrototypeOf(this).method(); },
>

That would only recurse if you do something stupid like

child.method = parent.method;

The problem with `.getPrototypeOf` is that you cannot skip a step in the
prototype chain easily. This is solved by designing your code and hierachy
properly.


>
> You'll crash the browser. Uber bummer!
> So, we need something a bit more comprehensive than that.
>
> As for your pd.make, yes, it's pretty much the same as Create.
> Create also lets you cache the resulted object in a function that will
> generate the same instance with every call, if you find it necessary.
> Like define once and construct multiple times.
>
> @Alexander:
> You're right, usually you wouldn't call an overridden property from a
> different one.
> The thing is, for now, this looks like the smallest, safest, most
> simple and least obtrusive way of getting a property.
> Besides naming a function and getting it from arguments.callee.caller,
> is there another way you see of getting that property?
>
> Thanks a lot guys!
> ~Y
>
>
> On Oct 25, 11:35 am, "Fyodorov &quot;bga&quot; Alexander"
> <bga.em...@gmail.com> wrote:
> > ydaniv:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > Thanks guys for the input!
> >
> > > @Jake:
> > > It's evil to extend Object.prototype with an enumerable property.
> > > here "_prototype_" is non-configurable because the logic here depends
> > > on it. If you choose to use this then you'd want it to be non-
> > > configurable.
> > > But perhaps you're right and I could add "configurable: true", seems
> > > like a good idea.
> >
> > > The "_asDescriptor" function is private and quite straight-forward.
> > > The use of the letters e, p &r is a physical joke, and I didn't think
> > > that following a single-line function would be too hard to follow.
> > > Anyhow, I guess I'll change those to something more meaningful.
> >
> > > I'm sorry that you see the supr function as magic, cause actually it
> > > follows the straight forward logic of getting an overridden property
> > > in a prototype chain:
> > > You find the object in the chain that actually defines this property
> > > and then get this property again from its parent.
> > > Since JS don't protect you from possible errors you need to go through
> > > some hoops.
> >
> > > What are Object.make & Object.createSimple?
> > > And yes, Create is very thin and light, that was the objective here.
> >
> > > @Alexander:
> > > As I mentioned in the docs, if you name each method you're using supr
> > > inside and not in strict mode then you can loose the "name" param.
> >
> > > Personally I don't like Resig's this._super because I find it very
> > > obtrusive, it bloats your code, and frankly it uses magic like using
> > > regex on the function.toString().
> >
> > > If you consider using a function's name inside it as breaking the DRY
> > > principle then I guess that's your opinion. In python, you call a
> > > super function like this:
> > > class C(B):
> > >     def method(self, arg):
> > >         super(C, self).method(arg)
> >
> > > You could say I took some inspiration from that.
> > > Besides that, putting a name of a different property allows you to
> > > call a different overridden property, which is not RY at all.
> >
> > > Thanks!
> > > ~Y
> >
> > > On Oct 24, 1:01 pm, "Fyodorov &quot;bga&quot; Alexander"
> > > <bga.em...@gmail.com> wrote:
> > > > ydaniv:
> >
> > > > > Hi,
> >
> > > > > I saw some discussions about OO & inheritance in JS so thought I
> might
> > > > > share a small Gist I've contrived:
> >
> > > > >https://gist.github.com/1074335
> >
> > > > > It's ES5 only and implements a simple wrap for the Object.create
> > > > > mechanism and a "super" property getter in a more unobtrusive way.
> >
> > > > > It's OS and will appreciate any feedback.
> >
> > > > > Thanks,
> > > > > ~Y
> >
> > > > this._super() is better then your method because you force me
> > > > duplicate method name, its not DRY
> >
> > ok, its flexible but if you design/decomposition require call some
> > random method from super classes, not exactly what you overwrite - its
> > mean that you have bad design or i dont know real use cases
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/jsmentors@jsmentors.com/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to