Setter methods chainable with value=undefined. Fixes #5571.#608
Setter methods chainable with value=undefined. Fixes #5571.#608gibson042 wants to merge 12 commits intojquery:masterfrom
Conversation
src/attributes.js
Outdated
There was a problem hiding this comment.
I don't think the solution is to make a 5 parameter long signature into a 6 parameter signature.
There was a problem hiding this comment.
Both modes of jQuery.access require: collection, key(s), getter/setter function. Setter mode additionally requires a value, plus toggling of what to do when value is a function (use directly or use return value per element) or undefined (no-op or pass to setter). Add in a parameter for telling jQuery.access if it is getting or setting, and that's seven—we're actually saving a parameter by guessing the mode from parameter values.
Maintaining current functionality, the only way I see to reduce the parameter count is by combining setter flags into an options dictionary or bitwise-accessed number.
Alternatively, the method could be streamlined. Would you accept something like this, which abandons the unused functionality of setting values to functions and/or undefined?
return jQuery.access( this, name, jQuery.prop, /*set?*/ arguments.length > 1, value);
Or perhaps this?
return value === undefined && arguments.length > 1 ? this : jQuery.access( this, name, jQuery.prop, value);
…get/set by arguments.length. Fixes jquery#5571.
src/core.js
Outdated
There was a problem hiding this comment.
Per feedback from @rwldrn, I have streamlined the parameter signature of jQuery.access, though I am not particularly happy with how it is now called. This touches on a tradeoff between byte count/DRY on one hand and readability/performance on the other.
-48/-1 bytes for .js/.min.js
-271/-377 bytes for .js/.min.js
-271/-377 bytes for .js/.min.js Updated .html(undefined) unit test for IE.
src/dimensions.js
Outdated
There was a problem hiding this comment.
{Height: "height", Width: "width"} => { Height: "height", Width: "width" } ... but still not sure why this change was made?
There was a problem hiding this comment.
To save 17 bytes in jquery.js and 9 in jquery.min.js. You said in comment 18 that you'd strongly oppose adding even a single byte of new code, so I was optimizing pretty aggressively.
|
Landed. 6c2a501 |
jquery.js: -271 bytes
jquery.min.js: -377 bytes
Includes a reorganization of getter/setter utility
jQuery.accessto place required parameters at the beginning of the list and allow for bulk operations.Affected methods:
attrpropcssdataheightwidthtexthtmloffsetscrollLeftscrollTopqueue