Ticket #451 (closed enhancement: wontfix)

Opened 5 years ago

Last modified 4 years ago

DOM helper: $id()

Reported by: FND Owned by: FND
Priority: minor Milestone: 2.4.2
Component: core Version:
Severity: trivial Keywords:
Cc:

Description (last modified by FND) (diff)

The attached patch introduces the $id() function* as a shortcut for document.getElementById().

Apart from being a convenience, this also saves ~2 kB of code.


* name tentative; chosen to prevent conflicts with Prototype's $() function

Attachments

ticket451.patch Download (4.8 KB) - added by FND 5 years ago.
updated patch to account for #475 and #481

Change History

Changed 5 years ago by FND

  • owner changed from JeremyRuston to FND
  • status changed from new to assigned

Changed 5 years ago by MartinBudden

  • milestone set to 2.4

Changed 5 years ago by MartinBudden

Patch to this needs revision to take into account changes made in ticket #475 and #481

Changed 5 years ago by FND

updated patch to account for #475 and #481

Changed 5 years ago by FND

  • description modified (diff)

Changed 5 years ago by FND

  • milestone changed from 2.4 to 2.3.1

Milestone changed to v2.3.1 to prevent additional work in the future (further core changes might require yet another revision of this patch).

Changed 5 years ago by MartinBudden

  • status changed from assigned to closed
  • resolution set to wontfix

Agreed not to implement in developer conference call. Instead we will add support for getElementsByClassName.

Changed 5 years ago by tbr

  • milestone changed from 2.3.1 to 2.5

Can you please elaborate (a bit) on the reason(s) for not implementing such a function? I believe this to be good js practice, hence desireable for future tw core/plugin development. One might even want to implement an extended version of the initially requested function, like the following:

function $() {
	var elems = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var el = arguments[i];
		if (typeof el == 'string')
			el = document.getElementById(el);
		if (arguments.length == 1)
			return el;
		elems.push(el);
	}
	return elems;
}

source:  http://www.dustindiaz.com/top-ten-javascript

Changed 5 years ago by FND

  • status changed from closed to reopened
  • resolution wontfix deleted

The original reasoning for rejecting this was that it is merely an abbreviation/redirection to shorten the code and/or reduce typing. (If we were to go down that path, we would start with functions other than getElementById(), e.g. createTiddlyElement()).

Might be worth revisiting now though...

Changed 5 years ago by FND

  • status changed from reopened to closed
  • resolution set to wontfix

To be superseded by jCore projected.

Changed 4 years ago by MartinBudden

  • milestone changed from 2.5 to 2.4.2
Note: See TracTickets for help on using tickets.