Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that when extending Easel display classes you should explicitly call initialize() #25

Closed
brandenhall opened this issue Feb 25, 2011 · 7 comments

Comments

@brandenhall
Copy link
Contributor

If initialize is not explicitly called then all sorts of things go wonky due to the fact that initialize() is where the display classes setup their children array and get assigned their UID.

@mikechambers
Copy link
Contributor

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?

@tommoor
Copy link

tommoor commented Feb 26, 2011

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
}

@gskinner
Copy link
Member

gskinner commented Mar 1, 2011

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.

@mikechambers
Copy link
Contributor

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.

@mikechambers
Copy link
Contributor

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.

@mikechambers
Copy link
Contributor

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).

@gskinner
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants