Skip to content

dherman/structs.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

structs.js

A prollyfill for the ES6 typed/structured objects API.

To use, include typedobjects.js in the lib directory.

Example:

var { StructType, ArrayType, uint32, float32 } = TypedObjects;

var Point = new StructType({ x: uint32, y: uint32 });
var Segment = new StructType({ start: Point, end: Point, opacity: float32 });
var Triangle = new ArrayType(Segment, 3);

var t = new Triangle([{ start: { x: 0, y: 0 },
                        end: { x: 10, y: 0 },
                        opacity: 0.5 },
                      { start: { x: 10, y: 0 },
                        end: { x: 5, y: 10 },
                        opacity: 1.0 },
                      { start: { x: 5, y: 10 },
                        end: { x: 0, y: 0 },
                        opacity: 0.3 }]);
// ...
t[2].opacity = 0.4;
t[0].start.x++;
// ...

Example:

var { StructType, uint32, float32, object } = TypedObjects;

var Widget = new StructType({ foo: uint32, bar: float32, baz: object });
var w = new Widget;
w.baz // null
w.baz = { quux: "xyzzx" };
w.foo = 12;

Note: lib/structs.js contains previous polyfill for a previous version of the spec. To use, include all files from lib directory (implementation depends on proxies).

License

Licensed under the MIT License.

About

A prollyfill for ES6 typed/structured objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published