BoxedExternal Summary Boxes an external value or reference as an internally-typed object. Description Consider the following: class Foo { private var _bar; public property function bar() { return _bar; } } The above code will break encapsulation. Even without a setter defined, the very fact that the reference to "bar" is escaped will violate encapsulation. Since externals can be any object or reference, it can be modified in unexpected ways. System.BoxedExternal is an internal type that boxes the external reference, so we can have references without exposing them as a naked external. The whole point of BoxedExternal is that a BoxedExternal cannot implicitly "escape" to JavaScript without first unboxing - which is much easier to detect. Examples Basic Usage 12345678import System; var obj = {}; BoxedExternal boxed = new BoxedExternal(obj); // var externalConversionAttempt1 = boxed; // ERRORvar externalConversionAttempt2 = boxed.unbox(); // OK, explicit unboxing Changing the boxed object at runtime 123456import System; var obj1 = {}, obj2 = {};BoxedExternal boxed = new BoxedExternal();boxed.box(obj1);boxed.box(obj2); System.Object API 1234567891011import System; void internalTypesOnly(System.Object obj) { Console.log(obj.toString());} var myExternal = {};BoxedExternal myInternal = new BoxedExternal(internalTypesOnly); // internalTypesOnly(myExternal); // ERRORinternalTypesOnly(myInternal); // OK Methods boxBoxes an external object to give it an internal type. BoxedExternal (Constructor)Constructs a System.BoxedExternal object. unboxUnboxes the boxed external object to give it an external type. Share HTML | BBCode | Direct Link