Comparing version 0.0.2 to 0.0.3
@@ -5,3 +5,3 @@ { | ||
"description": "A JavaScript library for creating complex objects and properties, intuitively.", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/Benvie/def", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -0,4 +1,16 @@ | ||
# define def | ||
A single function to make defining sets of properties simple. | ||
## Basic Usage | ||
First it needs to be attached to an object, preferably on a prototype which future objects will inherit from. | ||
var def = require('def'); | ||
def(myObject.prototype); | ||
// or expose it to all objects | ||
def(Object.prototype); | ||
Then it should be used directly on the target object which should have the properties, whether that object will be used as a prototype or a singleton. | ||
### named function only | ||
@@ -50,2 +62,3 @@ | ||
### dict | ||
@@ -77,2 +90,3 @@ | ||
## Private variables | ||
@@ -82,5 +96,19 @@ | ||
### simple private usage | ||
myObj.def({ | ||
myPrivate: { | ||
get: function(privateValue){ | ||
return privateValue; | ||
}, | ||
set: function(privateValue, newValue){ | ||
return newValue; // privateValue is set to whatever `set` returns | ||
} | ||
} | ||
}) | ||
### advanced private usage | ||
myObj.def({ | ||
myPrivate: { | ||
get: function(privateValue){ | ||
return privateValue.somePublicProperty; | ||
@@ -90,3 +118,3 @@ }, | ||
if (newValue.secreyKey === privateValue.unlockKey) | ||
return newValue; | ||
return newValue.newPublicProperty; | ||
} else { | ||
@@ -93,0 +121,0 @@ return privateValue.somePublicProperty; |
7788
121