mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 11:00:08 +00:00
more docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e69934fe16
commit
a32e904f8b
49
README.md
49
README.md
@ -196,6 +196,55 @@ handling.
|
|||||||
as restrict the use-cases for the constructor.
|
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
|
### Inheriting from native objects
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user