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

createElement as method of p5.element? #395

Closed
shiffman opened this issue Oct 17, 2014 · 5 comments
Closed

createElement as method of p5.element? #395

shiffman opened this issue Oct 17, 2014 · 5 comments

Comments

@shiffman
Copy link
Member

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

@futuremarc
Copy link
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

@lmccart
Copy link
Member

lmccart commented Jun 17, 2015

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?

@shiffman
Copy link
Member Author

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.

@futuremarc
Copy link
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.

@futuremarc
Copy link
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
Projects
None yet
Development

No branches or pull requests

6 participants