Skip to content

createElement as method of p5.element? #395

Closed

Description

@shiffman

I'm finding I'm doing this quite a bit in some examples:

var div = createDiv('');
var a = createA('#','somelink');
a.parent(div); 

I wonder if it would make sense to allow:

var div = createDiv('');
var a = div.createA('#', 'somelink');

I am not at all sure about this. . .

Activity

  1. self-assigned this
    on Jun 12, 2015
  2. futuremarc commented on Jun 16, 2015

    @futuremarc
    Contributor

    is there a better way to do this than to create copies of the methods but attach them to the p5.Element then rather than using addElement() to add it to the pInst we'll just use child() instead.

    I would use call() but the addElement() method seems to only add elements to pInst

  3. lmccart commented on Jun 17, 2015

    @lmccart
    Member

    I wonder if this is just a little too confusing? Right now all the create methods attach something to the DOM, I think it might make sense to stick with this just to make our lives easier on the development side? Or is this creating one element from another pattern something that's really common in JS?

  4. shiffman commented on Jun 17, 2015

    @shiffman
    MemberAuthor

    I'm not too keen on adding complexity so I agree this is probably something to leave out. The use case I am finding is that some of my examples do this alot:

    var elt1 = createElement();
    var elt2 = createElement();
    elt2.parent(elt1);
    

    So is this really any better or less confusing?

    var elt1 = createElement();
    var elt2 = elt1.createElement();
    

    Now that I write these, I think the answer is likely no. Or certainly not so great that it's worth the code and reference expanding.

  5. futuremarc commented on Jun 17, 2015

    @futuremarc
    Contributor

    I think I'd agree when comparing pros and cons; but during testing being able to create an element immediately as a child of another element feels great.

  6. futuremarc commented on Jun 20, 2015

    @futuremarc
    Contributor

    Closing this one as it doesn't make too much sense

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions