Skip to content

Confusion between .elt and .canvas #3156

Closed
@Zalastax

Description

@Zalastax

@Spongman highlights in #3155 that there is a confusion between the properties .elt and .canvas causing us to write defensive code like so:

cnv = img.canvas || img.elt;

What is the purpose of having both .elt and .canvas? How can it be that the canvas should sometimes come from .elt and sometimes from .canvas?

Searching for .canvas = I get these results:

this.canvas = document.createElement('canvas');

this.canvas = document.createElement('canvas');

this.canvas = elt;

this.canvas = document.createElement('canvas');

this._pInst.canvas = c;

Searching for .elt = I get these results:
this.elt = elt;

elt = this.elt = arg.elt;

elt = this.elt = existing_radios.elt;

and a comment about checking if the canvas is associated with the p5 instance

p5.js/lib/addons/p5.dom.js

Lines 1938 to 1939 in 5a46133

// main canvas associated with p5 instance
if (this._pInst._curElement.elt === this.elt) {

Some of the places that assign canvas also assign elt afterwards, some do not.
In #3155 @Spongman solves the problem via if (!this.canvas) this.loadPixels();, is that a general approach we should apply elsewhere?
Do we have a place where we can add (or already have?) YUIDocs for .elt and .canvas?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions