From a32e904f8bd810ccf3ccf7c1a64e2bf32c5ded24 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 2 May 2020 22:09:37 +0300 Subject: [PATCH] more docs... Signed-off-by: Alex A. Naanou --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index c33d14b..88938dc 100755 --- a/README.md +++ b/README.md @@ -196,6 +196,55 @@ handling. as restrict the use-cases for the constructor. +### Extending the constructor + +The `constructor.__proto__` should be callable. + +```javascript +var D = object.Constructor('D', + object.mixinFlat(function(){}, { + constructor_attr: 'some value', + + constructorMethod: function(){ + // ... + }, + + // ... + }), + { + instance_attr: 'some other value', + + instanceMethod: function(){ + var x = this.constructor.constructor_attr + + // ... + }, + + // ... + }) +``` + +Keeping the class prototype a function is not necessary, but not doing +so will break the `D instanceof Function` test. + +Here is another less strict approach but here `D.__proto__` will not be +callable: +```javascript +var D = object.Constructor('D', + { + __proto__: Function, + + // ... + }, + { + // ... + }) +``` + +Passing a simple object as a constructor prototype will work too, but +will not pass the `D instanceof Function` test and is not recommended. + + ### Inheriting from native objects ```javascript