Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic object properties #14

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

Conversation

albertz
Copy link

@albertz albertz commented Mar 27, 2014

I have the case that I have some complex objects which have dynamic properties (defined via get functions) in their prototypes.

Currently, because of the Object.prototype.hasOwnProperty check in stringify, attributes from parent prototypes wont be shown at all. That is simple to change and already almost always what you probably want (I guess).

However, for my use case, that change is of course not enough. I added some more code which checks if a property is defined via a get-function, via Object.getOwnPropertyDescriptor. The client shows this as a placeholder and if the user requests to show the property, the clients send such request to the server. To make that possible, you need to keep some reference to the object on the server in case for a later request. I have introduced a small and simple object cache, where I assign a new id to a new object. This id is sent to the client and the client uses this id in its requests. I also extended the jsencr function a bit to cover this.

@Silviu-Marian
Copy link
Owner

Hello there.

Thanks for giving time to this.
I'm going to try a local test, not sure what steps to follow.

@Silviu-Marian
Copy link
Owner

Ok so, I have the changes locally and need to test them.
Can you please provide a simple test pattern? How should this feature work?

There's a couple of bits I don't like and maybe we can make some changes.

@albertz
Copy link
Author

albertz commented Jun 10, 2014

You need dynamic attributes, like this:

obj = {};
Object.defineProperty(obj, 'dyn_attrib', {get: function() {
     return obj; // or whatever ...
} , enumerable:true});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants