Hi Andrey,
I have no idea why this inconsistent behavior is present. I am, however,
interested in your use case, beucase I do not see any good in passing a
function to Object.create. Typically, one does
var Parent = function() {};
var Child = function() {};
Child.prototype = Object.create(Parent.prototype); /* inheritance without
constructor execution */
So I wonder if your interest is based on curiosity, or some real-life
implementation where it is desirable to call Object.create(function(){}).
Note that weird things can happen:
var F = function() {};
F.prototype = function() {};
var f = new F();
"apply" in f; // true! you just "inherited" a function :)
Ondrej
2010/4/27 Andrey Fedorov <[email protected]>
> When playing with some JS in Chrome, I noticed that the native
> implementation of Object.create throws a TypeError exception (Object
> prototype may only be an Object or null) if a function object is passed
> in, like:
>
> Object.create(function () {})
>
> The error is both factually incorrect and inconsistent with Crockford's
> original implementation, which works fine, if you pass in a function (even
> in Chrome):
>
> Object.create = function (o) {
> function F() {}
> F.prototype = o;
> return new F();
> };
>
> Oddly enough, I'm only seeing this on the Linux and OSX versions of Chrome,
> not on Windows. Any ideas why this could be?
>
> - Andrey
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users