#12573 closed feature (plugin)
Better API for Extend
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
$.extend is a very useful function but it is hard to remember what is happening because depending on the arguments that you give it, it does completely different tasks.
Here is what I do to remember
ObjectUtils = { deepCopy: function(obj){ return $.extend(true, {}, obj); }, copy: function(obj){ return $.extend({}, obj); }, update: function(base, override){ //any keys in overrides that match keys in base will now //point to the override data. //any keys in overrides not in base will also be added to base //NOTE: no copies here! only updates to base $.extend(base, override); }, augment: function(base, extensions){ var args = Array.prototype.concat.apply([{}], arguments); return $.extend.apply($, args); }, deepAugment: function(base, extensions){ var args = Array.prototype.concat.apply([true,{}], arguments); return $.extend.apply($, args); } });
I know there are probably more things you can do with $.extend but these are very common tasks that could be highlighted with a simple wrapper function name.
Change History (6)
comment:1 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
You can keep the same API and add a thin wrapper around it like and I think code would be much more readable.
comment:3 Changed 10 years ago by
ahem... what I meant to say is keep the same API and add a thin wrapper around $.extend like I did in my comment
comment:4 Changed 10 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
comment:5 Changed 10 years ago by
Resolution: | → plugin |
---|---|
Status: | reopened → closed |
Sure, you're welcome to do that and create a plugin. The current API works well enough for our needs and there are plenty of alternatives like underscore or lodash if ours isn't good enough. Besides the size increase of adding the code itself, there's the cost and complexity of documentation and maintenance so it's not something I think we want to add.
comment:6 Changed 10 years ago by
I understand thanks to the both of you for a quick response. Cheers!
This API has existed for many years and a lot of code is written that relies on it.