forked from bmeck/node-overload
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bradley Meck
committed
May 27, 2010
1 parent
d67b0a3
commit ce710ea
Showing
1 changed file
with
29 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
node-watchable | ||
@exports | ||
Watchabe(onGet,onSet) - Supplies getter and setter callbacks across all the properties | ||
#node-watchable | ||
##exports | ||
* Watchable(onGet,onSet) | ||
Supplies getter and setter callbacks across all the properties | ||
Currently both callbacks are required | ||
|
||
@example | ||
//print out any property gets that use the . operator | ||
var debug = Watchable( | ||
function(propertyName,value,hadAlready){ | ||
//check the type of the object contained by value | ||
//undefined if no value, or number if using []'s with a number | ||
if(typeof value === "string") { | ||
sys.puts(propertyName); | ||
} | ||
return value; | ||
##example | ||
Code | ||
//print out any property gets that use the . operator | ||
var debug = Watchable( | ||
function(propertyName,value,hadAlready){ | ||
//check the type of the object contained by value | ||
//undefined if no value, or number if using []'s with a number | ||
if(typeof value === "string") { | ||
sys.puts(propertyName); | ||
} | ||
function(propertyName,oldValue,value,hadAlready) { | ||
return value; | ||
} | ||
) | ||
return value; | ||
} | ||
function(propertyName,oldValue,value,hadAlready) { | ||
return value; | ||
} | ||
) | ||
debug.hello | ||
debug[" world!"] | ||
Output | ||
hello | ||
world! | ||
|
||
##uses | ||
1. Debugging - Show what is being accessed / set | ||
2. False natives - refuse to allow properties to be set / got beyond a specified few |