archives

« Bugzilla Issues Index

#335 — a new Object.setProperty() method


Hello everyone!
My proposal is to implement a new Object method named "setProperty" (similar to the Object.defineProperty method) but which uses binary flags instead of a property descriptor object. Here is a possible example:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty#Example_.232:_a_new_custom_Object.setProperty%28%29_method

It could be very a very useful possibility if you have to define many properties of an object, because the Object.defineProperty() method is very expensive of code.


Created attachment 23
Object.setProperty() example


New link:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty#Example_.232:_create_a_new_non-native_Object.setProperty%28%29_method


The bit mask was consider and not adopted during the development of ES5. See http://wiki.ecmascript.org/lib/exe/fetch.php?id=es3.1%3Aes3.1_proposal_working_draft&cache=cache&media=es3.1:rationale_for_es3_1_static_object_methodsaug26.pdf


(In reply to comment #3)
> The bit mask was consider and not adopted during the development of ES5. See
> http://wiki.ecmascript.org/lib/exe/fetch.php?id=es3.1%3Aes3.1_proposal_working_draft&cache=cache&media=es3.1:rationale_for_es3_1_static_object_methodsaug26.pdf

Yes, of course regarding the Object.defineProperty() method... But, what's about a new faster method, like the Object.setProperty() of my example?

...when you have to define tens of new properties, the actual Object.defineProperty() method is too mutch expensive of code (I know this problem very well).

The official motivation is that a bitmask is difficult to remember... but... for a developer?? And it would be another, faster method, over and above the Object.defineProperty() method.