Skip to main content

Bug Tracker

Side navigation

#8322 closed bug (invalid)

Opened February 18, 2011 09:26PM UTC

Closed April 01, 2011 03:14AM UTC

remove the infinite-arguments signature from .append()-and-friends

Reported by: leeoniya@gmail.com Owned by:
Priority: low Milestone: 1.next
Component: manipulation Version: 1.5.1rc1
Keywords: Cc:
Blocked by: Blocking:
Description

please consider removing the undocumented infinite arguments signature from various Manipulation methods, since it makes them non-evolvable and unnecessarily locks down any useful signature additions in future versions of jQuery.

there's no need for infinite args being on a user-facing API. consider instead adding a signature of an array single-argument of elements to append as this only adds 2 characters [] to the syntax, and leaves many more options open for the future. for example:

$("body").append("<p/>",{id:"blah"}); // like jQuery()

rather than

$("body").append($("<p/>",{id:"blah"}));

more discussion here:

http://forum.jquery.com/topic/make-append-and-friends-create-elements-like-jquery

Attachments (0)
Change History (7)

Changed February 18, 2011 09:49PM UTC by kswedberg comment:1

Sorry, but the extra arguments are documented as of a couple days ago. Would it be possible to do a "plain object" check on the second arg and do your thing if it passes? That way we could leave the other multi-arg signature in place.

Changed February 18, 2011 10:11PM UTC by leeoniya@gmail.com comment:2

i understand they may be documented as of very recently, but they are not in wide use yet. therefore, it is not too late to un-document them in my opinion. i just don't see added benefit in having this at all, the signature itself is unlike 90% if not 99% of other jquery methods, and creates a scaffold for future method-cruft with a poor precedent.

of course it's possible to have that special-case check. but i agree with

Dave Methvin that a special case is not worth it. this would worse still than a bad, but predictable API.

these multiple arguments were never a trumpeted feature, and unveiling them so unceremoniously, then calling it finalized in its current state does not sit well with me at all.

Changed February 18, 2011 10:22PM UTC by dmethvin comment:3

I don't see a compelling need for additional signatures, they just make the API harder to understand. We all can certainly come up with new ones but unless there are significant benefits I would prefer to maintain backward compatibility.

Also there is code that depends on multi-arg, here's an imperfect search for it:

http://google.com/codesearch?hl=en&lr=&q=\\.(ap|pre)pend\\([^()]*,+lang:javascript+-extjs+-ckeditor

Changed February 18, 2011 10:43PM UTC by leeoniya@gmail.com comment:4

certainly this is not for any 1.5.x release, but leaving it undocumented (as before) would ease an already easy migration to maybe a 1.6 target - wrapping the arguments with an array is a trivial regex replace.

fear of breaking backwards compatibility of previously undocumented features is a strange concern at best. and an even stranger reason to retain what exists currently when it can easily be replicated in a more optimal manner.

i think this is a mistake going forward, not much else i can say.

$0.02 given

Changed February 19, 2011 07:35PM UTC by timmywil comment:5

I don't think it's a strange concern to keep an API that was introduced in jQuery 1.0. However, I've studied the manipulation code and do not believe it is very difficult to extend the api for append/prepend and even other dom manipulation methods as they all use the same function, as kswedberg has already suggested. See third party Pull Request

Changed February 20, 2011 01:39PM UTC by jitter comment:6

component: unfiledmanipulation
keywords: → needsreview
priority: undecidedlow

Changed April 01, 2011 03:14AM UTC by dmethvin comment:7

keywords: needsreview
resolution: → invalid
status: newclosed

We're keeping the multi-arg form of .append and friends since it has been around for five years.