mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
started work on ObjectWithAutoKeys(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
7363662c38
commit
2e66cb3083
@ -175,6 +175,34 @@ object.Constructor('UniqueKeyMap', Map, {
|
||||
})
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// XXX should this be a map???
|
||||
// XXX make two variants: ordered and unordered...
|
||||
var ObjectWithAutoKeys =
|
||||
module.ObjectWithAutoKeys =
|
||||
object.Constructor('ObjectWithAutoKeys', {
|
||||
|
||||
__last_key: null,
|
||||
__new_key__: function(value){
|
||||
return (this.__last_key = (this.__last_key || -1) + 1) },
|
||||
|
||||
//
|
||||
// .push(value)
|
||||
// -> key
|
||||
//
|
||||
// .push(value, ..)
|
||||
// -> [key, ..]
|
||||
push: function(...values){
|
||||
var that = this
|
||||
var res = values
|
||||
.map(function(value){
|
||||
that[that.__new_key__(value)] = value })
|
||||
return values.length == 1 ?
|
||||
res.pop()
|
||||
: res },
|
||||
})
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user