Last piece of code should be:
var derived2 = Object.create(derived);
derived2.construct = function() {
derived.construct.call(this);
};
derived2.construct();
missing "function()" and the closing semicolon in the declaration.
Diego
On Tue, Dec 27, 2011 at 1:18 PM, Jarek Foksa <[email protected]> wrote:
> "var derived = new base()" basically means:
>
> var derived = Object.create(base.prototype);
> derived.constructor = base;
> derived.constructor();
>
> Which could be further deconstructed into:
>
> var derived = {};
> derived.__proto__ = base.prototype;
> derived.constructor = base;
> derived.constructor();
>
> Which in turn is the same as:
>
> var base = {
> construct: function() {
> },
> }
> var derived = Object.create(base);
> derived.construct();
>
> The way how "new" keyword and object.prototype work is confusing and
> counterintuitive.
> I would highly recommend you to use the last technique if possible.
> You can create "derived2" object that inherits from "derived" object
> like this:
>
> var derived2 = Object.create(derived);
> derived2.construct = {
> derived.construct.call(this);
> }
> derived2.construct();
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]