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

Implement with Proxies #14

Open
paulirish opened this issue Feb 17, 2016 · 5 comments
Open

Implement with Proxies #14

paulirish opened this issue Feb 17, 2016 · 5 comments

Comments

@paulirish
Copy link
Owner

ES6 Proxies could be used to pull off the same technique. It perhaps could have a few advantages over using getters.

They're now in most browsers:
image

@sktguha
Copy link

sktguha commented Mar 1, 2016

👍

@paulirish
Copy link
Owner Author

Any help is appreciated!

@ashmind
Copy link
Collaborator

ashmind commented Mar 1, 2016

@paulirish Not sure it is possible in general case -- doesn't Proxy have to be a separate object? So it wouldn't help if you want to watch an object already referenced somewhere.

@paulirish
Copy link
Owner Author

@ashmind yeah true. the workflow is a little different.

I suppose we could do something like

Object.prototype.debug = function(){

var interceptor = {
  set: function (receiver, property, value) {
    console.trace(property, 'is changed to', value);
    // debugger
    receiver[property] = value;
  }
};

return new Proxy(this, interceptor);
}

which could enable creating the debuggable object at assignment:

this.latLon = app.getLon().debug();

.... oh look at that, somebody already wrote this: check tracePropAccess in http://www.2ality.com/2014/12/es6-proxies.html

@paulirish
Copy link
Owner Author

I suppose one benefit is that you can watch any properties, not just specified ones.

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

No branches or pull requests

3 participants