0

I'm attempting to implement the solution provided here, but apparently is conflicting with jquery as described in this ticket.

So far I dind't find a solution, any ideas?

I want to implement the inheritance mechanism proposed by Shelby Moore

This may be the cause of the problem, extending the Object prototype:

Object.prototype.Inherits = function(parent)
{
    if(arguments.length > 1)
    {
        parent.apply(this, Array.prototype.slice.call(arguments, 1));
    }
    else
    {
        parent.call(this);
    }
}

EDIT 1: After extensive reading I adopted the following pattern:

NewFunction.prototype = Object.create(new FunctionToInheritFrom());

2 Answers 2

3

Extending the Object.prototype extends all Objects, so your if you modify the prototype of all Objects you can brake their desired behavior and that is why one should avoid to modify to Object prototype directly. It is better practice to extend custom functions prototypes, that ensures not to brake other prototypes, i.e. provided by frameworks like jQuery. Even Objects that represent DOMElements are modified what is a bad idea in general.

Nevertheless I would like to mention that Javascript itself does not define real Inheritance and trying to work around this leads to a lot of problems and makes it more difficult to develop. Inheritance in Javascript is prototype based Inheritance, which is different from real Inheritance, facing this fact and using Javascripts own methods for "something like inheritance" (i.e. described here) is straight forward and works very good.

For me, Javascript inheritance is more like merging object-members and a very good article about this is this one of douglas crockford, I think it is worth reading.

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

1 Comment

+1 for mentioning that JavaScript isn't a classical OO language. Learn and love the language's way of doing things rather than trying to impose a mismatched model on to it.
0

i cant reproduce this thing.. and its working fine check this the code is simple like this

Object.prototype.Inherits = function(parent)
{
    if(arguments.length > 1)
    {
        parent.apply(this, Array.prototype.slice.call(arguments, 1));
    }
    else
    {
        parent.call(this);
    }
}
    $(document).ready(function(){
        $('input').click(function(){
     alert();
     });
    });

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.