-
Notifications
You must be signed in to change notification settings - Fork 18
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
kangax
authored and
kangax
committed
May 23, 2008
1 parent
8abdc3a
commit 9af0da0
Showing
3 changed files
with
45 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Array#namespace(parrent=window) -> Array | ||
* - parent(Object): top level object to start injection from | ||
* | ||
* Creates a nested chain of objects, based on the value of array items | ||
* | ||
* 'Prototype.foo.bar'.namespace(); | ||
* typeof Prototype.foo.bar; // => 'object' | ||
* 'util.DOM.dimensions'.namespace(Prototype); | ||
* typeof Prototype.util.DOM.dimensions; // => 'object' | ||
**/ | ||
String.prototype.namespace = function(parent) { | ||
return this.split('.').inject(parent || window, function(object, property) { | ||
return object[property] = object[property] || { }; | ||
}) | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
"http://www.w3.org/TR/html4/strict.dtd"> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
|
||
<title>helpers.js test file</title> | ||
|
||
<link rel="stylesheet" href="../lib/test.css" type="text/css" /> | ||
|
||
<script src="../lib/prototype.js" type="text/javascript"></script> | ||
<script src="../lib/unittest.js" type="text/javascript"></script> | ||
<script src="../array.extensions.js" type="text/javascript"></script> | ||
|
||
</head> | ||
<body> | ||
<div id="testlog"></div> | ||
|
||
<script type="text/javascript"> | ||
new Test.Unit.Runner({ | ||
testArrayPrototypeSum: function() { | ||
this.assertIdentical(6, [1,2,3].sum()); | ||
this.assertIdentical(10, ['1', 2, '3', 4, '', '', '', null, 0].sum()); | ||
} | ||
}) | ||
</script> | ||
|
||
</body> | ||
</html> |