Reputation: 50388
I have some custom properties on some of my objects, which I would like to keep unique per object.
Some third party code, however, is attempting to use jQuery to .extend some of my objects - with the deep-copy flag turned on.
I would like to prevent these properties from being deep copied. My intuition is to overwrite the jQuery.extend (and jQuery.fn.extend) functions, with functions which ignore my properties, but that sounds like overkill.
Upvotes: 0
Views: 696
Reputation: 50388
Properties added through
Object.defineProperty
with the enumerable argument set to false won't be caught by jQuery.extend.
a = { b: 'b'};
Object.defineProperty(a,'bb',{ get: function() {return "bb";},enumerable: false});
c = {};
jQuery.extend(c,a,a,a,a);
a.b // "b"
a.bb // "bb"
c.b // "b"
c.bb // undefined
Upvotes: 1