mirror of
https://github.com/flynx/object.js.git
synced 2025-12-19 18:01:40 +00:00
some formatting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f5bd427ed8
commit
e1d07053fc
41
object.js
41
object.js
@ -3,7 +3,8 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX should this extend Object???
|
* XXX should this extend Object???
|
||||||
* ...if yes then it would also be logical to move Object.run(..) here
|
* ...if yes then it would also be logical to move Object.run(..)
|
||||||
|
* here...
|
||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||||
@ -22,10 +23,10 @@ module.TAB_SIZE = 4
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// This will remove common indent from each like of text, this is useful
|
// This will remove common indent from each like of text, this is useful
|
||||||
// for printing function code of functions that were defined at deep levels
|
// for printing function code of functions that were defined at deep
|
||||||
// of indent.
|
// levels of indent.
|
||||||
//
|
//
|
||||||
// NOTE: this will trim out both leading and trailing whitespace.
|
// NOTE: this will trim out both leading and trailing white-space.
|
||||||
//
|
//
|
||||||
// XXX is this the right place for this???
|
// XXX is this the right place for this???
|
||||||
// ...when moving take care that ImageGrid's core.doc uses this...
|
// ...when moving take care that ImageGrid's core.doc uses this...
|
||||||
@ -146,7 +147,8 @@ function(obj, name, callback){
|
|||||||
// var a = object.parent(X.prototype, 'attr')
|
// var a = object.parent(X.prototype, 'attr')
|
||||||
//
|
//
|
||||||
// // get method...
|
// // get method...
|
||||||
// var ret = object.parent(X.prototype.method, this).call(this, ...arguments)
|
// var ret = object.parent(X.prototype.method, this)
|
||||||
|
// .call(this, ...arguments)
|
||||||
//
|
//
|
||||||
// // ...
|
// // ...
|
||||||
// }
|
// }
|
||||||
@ -301,8 +303,8 @@ function(root, ...objects){
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// NOTE: context is only passed to .__new__(..) if defined...
|
// NOTE: context is only passed to .__new__(..) if defined...
|
||||||
// NOTE: as this simply an extension to the base JavaScript protocol this
|
// NOTE: as this simply an extension to the base JavaScript protocol
|
||||||
// can be used to construct using any object...
|
// this can be used to construct using any object...
|
||||||
// Example:
|
// Example:
|
||||||
// var O = function(){}
|
// var O = function(){}
|
||||||
// // new is optional...
|
// // new is optional...
|
||||||
@ -332,14 +334,16 @@ function(context, constructor, ...args){
|
|||||||
: constructor.prototype instanceof Function ?
|
: constructor.prototype instanceof Function ?
|
||||||
_mirror_doc(
|
_mirror_doc(
|
||||||
function(){
|
function(){
|
||||||
return constructor.prototype.call(obj, this, ...arguments) },
|
return constructor.prototype
|
||||||
|
.call(obj, this, ...arguments) },
|
||||||
constructor.prototype)
|
constructor.prototype)
|
||||||
// callable instance -- prototype defines .__call__(..)...
|
// callable instance -- prototype defines .__call__(..)...
|
||||||
// NOTE: we need to isolate the .__call__ from instances...
|
// NOTE: we need to isolate the .__call__ from instances...
|
||||||
: constructor.prototype.__call__ instanceof Function ?
|
: constructor.prototype.__call__ instanceof Function ?
|
||||||
_mirror_doc(
|
_mirror_doc(
|
||||||
function(){
|
function(){
|
||||||
return constructor.prototype.__call__.call(obj, this, ...arguments) },
|
return constructor.prototype.__call__
|
||||||
|
.call(obj, this, ...arguments) },
|
||||||
constructor.prototype.__call__)
|
constructor.prototype.__call__)
|
||||||
// default object base...
|
// default object base...
|
||||||
: {}
|
: {}
|
||||||
@ -463,12 +467,12 @@ function(context, constructor, ...args){
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Motivation:
|
// Motivation:
|
||||||
// The general motivation here is to standardise the constructor protocol
|
// The general motivation here is to standardise the constructor
|
||||||
// and make a single simple way to go with minimal variation. This is due
|
// protocol and make a single simple way to go with minimal variation.
|
||||||
// to the JavaScript base protocol though quite simple, being too flexible
|
// This is due to the JavaScript base protocol though quite simple,
|
||||||
// making it very involved to produce objects in a consistent manner by
|
// being too flexible making it very involved to produce objects in a
|
||||||
// hand, especially in long running projects, in turn spreading all the
|
// consistent manner by hand, especially in long running projects,
|
||||||
// refactoring over multiple sites and styles.
|
// in turn spreading all the refactoring over multiple sites and styles.
|
||||||
//
|
//
|
||||||
// This removes part of the flexibility and in return gives us:
|
// This removes part of the flexibility and in return gives us:
|
||||||
// - single, well defined protocol
|
// - single, well defined protocol
|
||||||
@ -478,8 +482,8 @@ function(context, constructor, ...args){
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// NOTE: this sets the proto's .constructor attribute, thus rendering it
|
// NOTE: this sets the proto's .constructor attribute, thus rendering it
|
||||||
// not reusable, to use the same prototype for multiple objects clone
|
// not reusable, to use the same prototype for multiple objects
|
||||||
// it via. Object.create(..) or copy it...
|
// clone it via. Object.create(..) or copy it...
|
||||||
// NOTE: to disable .__rawinstance__(..) handling set it to false in the
|
// NOTE: to disable .__rawinstance__(..) handling set it to false in the
|
||||||
// class prototype... (XXX EXPERIMENTAL)
|
// class prototype... (XXX EXPERIMENTAL)
|
||||||
//
|
//
|
||||||
@ -523,7 +527,8 @@ function Constructor(name, a, b){
|
|||||||
var args = proto.__init__ ?
|
var args = proto.__init__ ?
|
||||||
proto.__init__
|
proto.__init__
|
||||||
.toString()
|
.toString()
|
||||||
.split(/\n/)[0].replace(/function\(([^)]*)\){.*/, '$1')
|
.split(/\n/)[0]
|
||||||
|
.replace(/function\(([^)]*)\){.*/, '$1')
|
||||||
: ''
|
: ''
|
||||||
var code = proto.__init__ ?
|
var code = proto.__init__ ?
|
||||||
proto.__init__
|
proto.__init__
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user