From b77550f97f7922465ea74bd738e961b2048248a6 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 27 Oct 2022 01:52:27 +0300 Subject: [PATCH] made things a bit more obvious: .data -> .proto Signed-off-by: Alex A. Naanou --- object.js | 40 ++++++++++++++++++++-------------------- package.json | 2 +- test.js | 10 +++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/object.js b/object.js index 5181362..d26a8a7 100755 --- a/object.js +++ b/object.js @@ -1208,11 +1208,11 @@ function(base, ...objects){ // Mixin wrapper/object... // // Create a new mixin... -// Mixin(name, data, ..) +// Mixin(name, proto, ..) // -> mixin // // Create a new mixin setting the default mode... -// Mixin(name, mode, data, ..) +// Mixin(name, mode, proto, ..) // -> mixin // // @@ -1242,7 +1242,7 @@ function(base, ...objects){ // BasicMixin(o) // // -// NOTE: the constructor will allways create a new .data object but will +// NOTE: the constructor will allways create a new .proto object but will // not do a deep copy into it -- see mixin(..) / mixinFlat(..) // // XXX should this move to its own modue??? @@ -1262,38 +1262,38 @@ Constructor('Mixin', { }, { name: null, - // mixin data... - data: null, + // mixin proto... + proto: null, - // data "copy" mode... + // proto "copy" mode... // // This can be: - // 'proto' - mix data into prototype chain (default) - // 'flat' - use mixinFlat(..) to copy data + // 'proto' - mix proto into prototype chain (default) + // 'flat' - use mixinFlat(..) to copy proto // 'soft' - like 'flat' but uses mixinFlat('soft', ..) mode: 'proto', // base API... // isMixed: function(target){ - return this.constructor.hasMixin(target, this.data) }, + return this.constructor.hasMixin(target, this.proto) }, mixout: function(target){ - return this.constructor.mixout(target, this.data) }, + return this.constructor.mixout(target, this.proto) }, // mix into target... __call__: function(_, target, mode=this.mode){ typeof(target) == typeof('str') && ([_, mode, target] = arguments) return mode == 'flat' ? - this.constructor.mixinFlat(target, this.data) + this.constructor.mixinFlat(target, this.proto) : mode == 'soft' ? - this.constructor.mixinFlat('soft', target, this.data) - : this.constructor.mixin(target, this.data) }, + this.constructor.mixinFlat('soft', target, this.proto) + : this.constructor.mixin(target, this.proto) }, - __init__: function(name, ...data){ + __init__: function(name, ...proto){ // Mixin(name, mode, ...) -- handle default mode... - typeof(data[0]) == typeof('str') - && (this.mode = data.shift()) + typeof(proto[0]) == typeof('str') + && (this.mode = proto.shift()) // name... // NOTE: .defineProperty(..) is used because this is a function // and function's .name is not too configurable... @@ -1303,12 +1303,12 @@ Constructor('Mixin', { // XXX is this effective??? // ...will this show up in DevTools??? Object.defineProperty(this, 'name', { value: name }) - // create/merge .data... - this.data = this.constructor.mixinFlat({}, - ...data.map(function(e){ + // create/merge .proto... + this.proto = this.constructor.mixinFlat({}, + ...proto.map(function(e){ // handle bare objects and mixins differently... return e instanceof Mixin ? - e.data + e.proto : e })) }, }) diff --git a/package.json b/package.json index 1601f33..eaef069 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "6.1.4", + "version": "6.2.0", "description": "", "main": "object.js", "scripts": { diff --git a/test.js b/test.js index 917b272..6251833 100755 --- a/test.js +++ b/test.js @@ -737,13 +737,13 @@ var cases = test.Cases({ var A = assert(object.Mixin('A', { a: 'aaa', }), 'Mixin("A", ...)') - assert(A.data.a == 'aaa', 'A content') + assert(A.proto.a == 'aaa', 'A content') assert(A.mode == 'proto', 'A mode') var B = assert(object.Mixin('B', 'flat', { b: 'bbb' }), 'Mixin("B", "flat", ..)') - assert(B.data.b == 'bbb', 'B content') + assert(B.proto.b == 'bbb', 'B content') assert(B.mode == 'flat', 'B mode') var C = assert(object.Mixin('C', @@ -753,9 +753,9 @@ var cases = test.Cases({ get c(){ return 'ccc' }, }), 'Mixin("C", A, B, ...)') - assert(C.data.a == 'aaa', 'C content from A') - assert(C.data.b == 'bbb', 'C content from B') - assert(C.data.c == 'ccc', 'C content local') + assert(C.proto.a == 'aaa', 'C content from A') + assert(C.proto.b == 'bbb', 'C content from B') + assert(C.proto.c == 'ccc', 'C content local') var x = assert(C({}), 'C({})')