Update to “Inheritance in JavaScript”

Surprisingly, I’m seeing more and more traffic to my “Inheritance in JavaScript” tutorial. As that traffic has increased, there have been a number of legitimate complaints about my use of an “init” method to initialize base classes and child classes. I found a way around that last October, so I thought it was high time to incorporate that approach into the tutorial. So, if you find C#/Java-style OOP in JavaScript interesting (or at least not offensive), then you may enjoy my latest updated tutorial.

http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm

Special thanks go to Robin Debreuil - aka. The Prototype Master - for suggesting how to get around the use of “init”. Also, special thanks to Peter Michaux (and many others) for gently prodding me to update my tutorial.

5 Responses to “Update to “Inheritance in JavaScript””

  1. Jon Says:

    Sweet, thanks. You are still the man.

  2. Dan Says:

    Kevin,

    Your work is incredible. Still, I want to know, what method are you using to solve bezier intersections? I’m trying to do it myself and having a bad time.

    Thanks very much
    Dan

  3. Thelonious Says:

    Hi Dan,

    Thanks for the feedback! It’s been a long time since I wrote that intersection code, but I’ll see if I can remember the general idea. I’ll assume you’re refering to the various bezier-bezier intersections as opposed to say the bezier-line intersection.

    First off, I got a huge amount of help from David Eberly. I’m using a fair amount of his algorithms for the actual root finding since they appear to work well in my limited usage of them. Also, he pointed me to an article called “Elimination and Resultants”. It was well worth the money buying that article.

    So, basically the process is to convert the bezier from Berstein polynomials to their equivalent quadratic or cubic polynomials, one for each axis. From there, I find the Bezout determinant and solve for one of the unknowns. I plug each of the roots of that polynomial into the other unknown’s polynomial. Each value that gives me zero in both polynomials is an intersection. I tried to be pretty thorough with my comments in the quadraticBezier-quadraticBezier intersection. You may find that code helpful. See Intersection.intersectBezier2Bezier2 line 113.

    One thing I should mention. Originally, I used MuPad and Mathematica to do all the math. That’s why you see all that ugliness in intersectBezier3Bezier3. I decided to make the code more readable by performing the steps explicitly in code like you see in intersectBezier2Bezier2. However, I must be getting underflows/overflows in the floating point which caused failures with the cubic beziers. Some day I’ll try to analyze the code to see how that can be remedied.

    HTH,
    Kevin

  4. Dan Says:

    Kevin,

    Thanks for replying. I’ve made an attempt at implementing your algorithm in Java (using double precision), see here:

    http://boredgamer.org/BezierPain.java

    It doesn’t work, though. I’ve been over and over your javascript and I can’t find the problem…

    Dan

  5. Jeroen Says:

    I am pleased to notice that other people promote a C#/Java-style OOP in JavaScript (which indeed may be subject to discussion ;-) . For that reason, I enjoyed reading your tutorial!
    Last year, I have created a small shareware library around the concepts that you mention in your tutorial. If you are interested, you can download it at http://software.antrix.nl/

    Jeroen