Git Product home page Git Product logo

Comments (7)

mikechambers avatar mikechambers commented on July 23, 2024

Should we have developers explicitly call initialize? or just explicitly call the super class constructor from the constructor of the extending class?

i.e.

function MyDisplayObject()
{
    DisplayObject.call(this);
}

MyDisplayObject.prototype = new DisplayObject();

Thoughts?

from easeljs.

tommoor avatar tommoor commented on July 23, 2024

That syntax is certainly neater than that used in the examples bundled with Easel at the moment. Are there any disadvantages over the current suggested?

Child.prototype = new Parent();
Child.prototype._super = Child.prototype.initialize;
Child.prototype.initialize = function() {
    this._super(); // call parent constructor
}

from easeljs.

gskinner avatar gskinner commented on July 23, 2024

I think that for now, we should address this with documentation. We can re-evaluate this for v0.4. See the Game example (Ship.js and SpaceRock.js) for a functional example of extending existing display objects.

from easeljs.

mikechambers avatar mikechambers commented on July 23, 2024

The question is what do we document?

I think:

function MyDisplayObject()
{
    DisplayObject.call(this);
}

MyDisplayObject.prototype = new DisplayObject();

Is clearer and easier to understand than:

Child.prototype = new Parent();
Child.prototype._super = Child.prototype.initialize;
Child.prototype.initialize = function() {
    this._super(); // call parent constructor
}

It also requires less internal knowledge about how the base class is implemented.

However, perhaps there is a functional difference between the two that is not immediately obvious to me.

from easeljs.

mikechambers avatar mikechambers commented on July 23, 2024

The question is what do we document?

I think:

function MyDisplayObject()
{
    DisplayObject.call(this);
}

MyDisplayObject.prototype = new DisplayObject();

is clearer and easier to understand than:

Child.prototype = new Parent();
Child.prototype._super = Child.prototype.initialize;
Child.prototype.initialize = function() {
    this._super(); // call parent constructor
}

It also requires less internal knowledge about how the base class is implimented.

However, perhaps there is a functional difference between the two that is not immediately obvious to me.

from easeljs.

mikechambers avatar mikechambers commented on July 23, 2024

We are moving this to the 0.4.0 release, so we have some more time to discuss the issue (as well as what the recommended approach for inheritance is).

from easeljs.

gskinner avatar gskinner commented on July 23, 2024

I have added a tutorial that specifically addresses this. I'm also going to think further about the ParentClass.call() approach.

from easeljs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.