mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
added .__new__(..)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b3f45390ce
commit
8286b42df6
15
object.js
15
object.js
@ -156,10 +156,13 @@ function(root, ...objects){
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Init protocol:
|
// Init protocol:
|
||||||
// 1) the base instance object is prepared (.__proto__ is set)
|
// 1) the base instance object is created
|
||||||
// 2) if <init-func> is present, then it is called with instance as
|
// 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
|
// 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.
|
// as context and passed the constructor arguments.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -247,7 +250,9 @@ function makeConstructor(name, a, b){
|
|||||||
// in...
|
// in...
|
||||||
// This is equivalent to:
|
// This is equivalent to:
|
||||||
// return new _constructor(json)
|
// return new _constructor(json)
|
||||||
var obj = {}
|
var obj = _constructor.prototype.__new__ instanceof Function ?
|
||||||
|
_constructor.prototype.__new__({}, ...arguments)
|
||||||
|
: {}
|
||||||
obj.__proto__ = _constructor.prototype
|
obj.__proto__ = _constructor.prototype
|
||||||
// XXX for some reason this does not resolve from .__proto__
|
// XXX for some reason this does not resolve from .__proto__
|
||||||
// XXX this also is a regular attr and not a prop...
|
// XXX this also is a regular attr and not a prop...
|
||||||
@ -264,7 +269,7 @@ function makeConstructor(name, a, b){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load initial state...
|
// load initial state...
|
||||||
if(obj.__init__ != null){
|
if(obj.__init__ instanceof Function){
|
||||||
obj.__init__.apply(obj, arguments)
|
obj.__init__.apply(obj, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "1.4.0",
|
"version": "1.5.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user