You should put up your idea as a blog post.
–
Corv1nusJul 31 '10 at 0:15

Objects created with your "from()" function passed a null do indeed inherit from Object.
–
PointyJul 31 '10 at 0:16

Oops.. my first version of this post used _proto_ instead and from(null) did not inherit from Object. I've got to go now, but I'll fix that later...
–
NickJul 31 '10 at 0:23

@Pointy I've given up on trying to find a way to set _proto_ to null (without actually using _proto_). I cannot find a cross-browser method. I've even tried Object = undefined, but apparently it's still there when you check the constructor of a function.
–
NickJul 31 '10 at 4:00

1

IMHO a global is not worse than an augmented Function prototype. Whatever... you could use Object.createChild or something, because quite frankly your from method is syntactic horror, as you noticed :) BTW: Don't use Object.create, because this will be defined in ECMAScript 5
–
user123444555621Jul 31 '10 at 18:07

with the same results as above.
Bonus: You can omit the constructor argument, like this:

var c = Object.createChild(anything);

Second, I don't know if there's any use for true prototypal inheritance, as you call it. In real life, I'm pretty sure the constructor function is particularly tailored to the object that's about to be extended (a). Thus, you're gonna end up calling

var x = f.from(a);
var y = f.from(a);

with the very same f-a combination over and over again. And yes, you save some bytes of memory as compared to a class-driven approach, but honestly, who cares?

You make some good points. I can agree that prototypal inheritance is something that is more useful in theory than practice (in fact, I never really need inheritance in my projects, so I just use the module pattern), but my idea was basically a way to try and make prototypal inheritance more useful. You get the benefits of private instance variables as well as inheritance capabilities without too much "hacking" the language (like all those libraries with pseudo-classes).
–
NickJul 31 '10 at 21:22

Personally, I like the idea of creating "classes" from objects. Your idea is good to do that, with slight modifications. Put constructor inside F's body, and return F. This is somewhat similar to ExtJS's extend method, which I find very useful.
–
user123444555621Aug 1 '10 at 6:37