Limiting Object.Prototype Possible?

Skoðað 14 sinnum
Fara í fyrstu ólesnu skilaboð

Brandon Jonson

ólesið,
8. jún. 2016, 16:27:568.6.2016
til v8-users
I've added custom code that extends Object to include a few other functions. Of course anybody could now go in and overwrite those or add their own functions simply by doing Object.Prototype.xxx = xxx. Is there an official way of locking that ability in V8 so at least the functions added could not be overwritten?

Thanks!

Spencer Killen

ólesið,
13. jún. 2016, 20:22:0913.6.2016
til v8-u...@googlegroups.com
In javascript you can use property descriptors to prevent overwriting. I'd imagine you could get v8 to set them on your functions


On Wed, Jun 8, 2016 at 2:27 PM, Brandon Jonson <brandon....@gmail.com> wrote:
I've added custom code that extends Object to include a few other functions. Of course anybody could now go in and overwrite those or add their own functions simply by doing Object.Prototype.xxx = xxx. Is there an official way of locking that ability in V8 so at least the functions added could not be overwritten?

Thanks!

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Spencer wrote this

Brandon Jonson

ólesið,
14. jún. 2016, 11:57:0114.6.2016
til v8-users
Hey Spencer,

Thanks for responding to this! This worked like a charm. Looks like I need to do a better job at reading the docs. 

This bare minimum worked with some caveats...

Object.defineProperty(Object.Prototype, 'nameOfFunction', {
  enumerable: false,
  configurable: false,
  writable: false,
  value: function() {
    //do work, return
    return "hello world";
  }
});
Svara öllum
Svara höfundi
Senda áfram
0 ný skilaboð