1

Using the new symbol type in ES6 you can set non-iterable properties on objects. However when using Knockout these symbols are not observed by default.

It is possible to bind a symbol's value, but it is never updated as it isn't added to the observable object.

Has anyone been able to work around this problem and force Knockout to observe symbols?

3
  • 2
    In case you need symbols only to define non-enumerable properties: You can also set them via defineProperty with an enumerable: false descriptor.
    – nils
    Oct 29, 2015 at 12:25
  • Can you show the ES6 code, and how you're doing the binding?
    – JotaBe
    Oct 29, 2015 at 15:41
  • Do you mean non-enumerable properties? Oct 29, 2015 at 16:31

1 Answer 1

2

Looks like the observable plugin for Durandal is implemented similarly to the Knockout-ES5 plugin. When applied to a view model it's only going to create observables wrapped in a getter/setter for properties that are enumerable on the object.

observable.defineProperty doesn't accept enumerable as a param but it does have configuration: true. This means that we can use observable.defineProperty (which will make the property enumerable) but then immediately make the property non-enumerable like so...

Object.defineProperty(this, 'myProp', { enumerable: false });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.