added .__new__(..)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-07-16 18:01:31 +03:00
parent b3f45390ce
commit 8286b42df6
3 changed files with 11 additions and 6 deletions

0
README.md Normal file → Executable file
View File

View File

@ -156,10 +156,13 @@ function(root, ...objects){
//
//
// Init protocol:
// 1) the base instance object is prepared (.__proto__ is set)
// 2) if <init-func> is present, then it is called with instance as
// 1) the base instance object is created
// 2) if .__new__(..) is defined it is passed to it along with the
// constructor arguments and the return value is used as base instance.
// 2) the base instance object is prepared (.__proto__ is set)
// 3) if <init-func> is present, then it is called with instance as
// context and passed the constructor arguments
// 3) if <proto>.__init__(..) is present, it is called with the instance
// 4) if <proto>.__init__(..) is present, it is called with the instance
// as context and passed the constructor arguments.
//
//
@ -247,7 +250,9 @@ function makeConstructor(name, a, b){
// in...
// This is equivalent to:
// return new _constructor(json)
var obj = {}
var obj = _constructor.prototype.__new__ instanceof Function ?
_constructor.prototype.__new__({}, ...arguments)
: {}
obj.__proto__ = _constructor.prototype
// XXX for some reason this does not resolve from .__proto__
// XXX this also is a regular attr and not a prop...
@ -264,7 +269,7 @@ function makeConstructor(name, a, b){
}
// load initial state...
if(obj.__init__ != null){
if(obj.__init__ instanceof Function){
obj.__init__.apply(obj, arguments)
}

View File

@ -1,6 +1,6 @@
{
"name": "ig-object",
"version": "1.4.0",
"version": "1.5.0",
"description": "",
"main": "object.js",
"scripts": {