Developer Tips Thread
#8
(2016-12-14, 02:47 AM)fizz Wrote: Haha that gravedig Big Grin

Necro bumping? lol



Here's a tip:

Always write code with extension in mind. For example, recently I developed a fiddle to be used internally by a group of developers. They wanted to optionally include several of their favorite JS libraries. Rather than writing:

if (data.jquery === true) {
	$("#jQueryCheck").prop("checked", true);
}

OR

$("#jqueryCheck").prop("checked", data.jquery === true ? true, false);

...for every library (there were several), write something like this:

$(["jquery", "jqueryui", "prototype", "scriptaculous", "etc", "etc"]).each(function() {
	$("#" + this + "Check").prop("checked", data.[this] === true ? true, false);
}

While it is a little harder to read, it makes extension as easy as adding another name to an array and of course, creating relevant code and elements.
[retired]
Reply


Messages In This Thread
Developer Tips Thread - by Wildcard - 2013-08-17, 05:35 PM
RE: Developer Tips Thread - by Destroy666 - 2013-08-17, 09:24 PM
RE: Developer Tips Thread - by Wildcard - 2013-09-25, 04:19 AM
RE: Developer Tips Thread - by Nathan Malcolm - 2013-09-25, 04:33 AM
RE: Developer Tips Thread - by Wildcard - 2013-09-25, 04:53 AM
RE: Developer Tips Thread - by Wildcard - 2016-12-11, 04:02 PM
RE: Developer Tips Thread - by fizz - 2016-12-14, 02:47 AM
RE: Developer Tips Thread - by Wildcard - 2016-12-16, 01:01 PM
RE: Developer Tips Thread - by Wildcard - 2017-01-02, 10:13 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)