2

Im new to oo concepts using javascript. From ejohn.org simple-inheritance

Standard Prototypal Inheritance

function Person(){}
function Ninja(){}
Ninja.prototype = new Person();
// Allows for instanceof to work:
(new Ninja()) instanceof Person

Statement from website over the above

What's challenging about this, though, is that all we really want is the benefits of 'instanceof', not the whole cost of instantiating a Person object and running its constructor. To counteract this we have a variable in our code, initializing, that is set to true whenever we want to instantiate a class with the sole purpose of using it for a prototype.

What does the above statement mean?

What are all the advantages of simple-inheritance by john-resig over standard prototypal inheritance?

var fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/

What is this above test for?

Can anyone explain the flow of the self-executing function? Although the code is annotated I couldn't follow the flow

1 Answer 1

2

It means, we can instantiate a class to use instanceof without having to invoke its faux constructor function init.

Fred provides an answer to your second query...

The xyz test determines whether the browser can inspect the textual body of a function. If it can, you can perform an optimization by only wrapping an overridden method if it actually calls this._super() somewhere in its body. Since it requires an additional closure and function call overhead to support _super, it’s nice to skip that step if it isn’t needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.