123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- "use strict";
- module.metadata = {
- "stability": "deprecated"
- };
- function get(object, name) {
- return object[name];
- }
- function set(object, name, value) {
- return object[name] = value;
- }
- function createAliasProperty(object, name) {
-
-
- var property = Object.getOwnPropertyDescriptor(object, name);
- var descriptor = {
- configurable: property.configurable,
- enumerable: property.enumerable,
- alias: true
- };
-
-
-
-
- if ("get" in property && property.get)
- descriptor.get = property.get.bind(object);
- if ("set" in property && property.set)
- descriptor.set = property.set.bind(object);
-
-
- if ("value" in property) {
-
- if (typeof property.value === "function") {
- descriptor.value = property.value.bind(object);
-
- descriptor.writable = property.writable;
- }
-
-
-
- else {
- descriptor.get = get.bind(null, object, name);
- descriptor.set = set.bind(null, object, name);
- }
- }
- return descriptor;
- }
- // Defines property on `object` object with a name `alias` if given if not
- // defaults to `name` that represents an alias of `source[name]`. If aliased
- // property was an assessor or a method `this` pseudo-variable will be `source`
- // when invoked. If aliased property was a data property changes on any of the
- // aliases will propagate to the `source[name]` and also other way round.
- function defineAlias(source, target, name, alias) {
- return Object.defineProperty(target, alias || name,
- createAliasProperty(source, name));
- }
- exports.Cortex = function Cortex(object, names, prototype) {
-
-
-
-
-
- var cortex = Object.create(prototype || Object.getPrototypeOf(object));
-
-
-
-
- Object.getOwnPropertyNames(object).forEach(function (name) {
- if ((!names && "_" !== name.charAt(0)) || (names && ~names.indexOf(name)))
- defineAlias(object, cortex, name);
- });
- return cortex;
- }
|