Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Cannot use Action/Function in PropertBag in JScript/V8

$
0
0
Hi egooner,

Why can I not access the PropertyBag's own Keys function is that intentional?

Yes, that's intentional. Property bags are special in that they expose their keys as if they were members. Exposing their members within the same namespace could create conflict or ambiguity.

If you need to enumerate a property bag, you can use JavaScript's for...in statement.

Another possibility is to expose a property bag's dictionary interface separately from the property bag itself:
var foo = new PropertyBag();
engine.AddHostObject("foo", foo);
engine.AddRestrictedHostObject("fooDict", (IDictionary<string, object>)foo);
and then, in JavaScript:
foo.bar = 123;
if (fooDict.Keys.Contains('bar')) {
    // do something
}
Cheers!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>