The Flow namespace, Array Extras, Plugin support, and other goodies.
1.0
Sets a few Browser/DOM flags.
These are more for internal use than external. The entire goal of Flow Core is that you don’t need to worry about browser detection.
| Flow.Browser.IE | Internet Explorer. |
| Flow.Browser.IE5 | Internet Explorer 5 |
| Flow.Browser.IE6 | Internet Explorer 6 |
| Flow.Browser.IE7 | Internet Explorer 7 |
| Flow.Browser.GK | Gecko-based |
| Flow.Browser.WK | Webkit |
| Flow.Browser.S3 | Safari 3 |
| Flow.Browser.OP | Opera |
A collection of Array Extras.
http://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Global_Objects:Array:every
| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
var isBigEnough = function(element, index, array) {
return (element >= 10);
};
var passed = [12, 5, 8, 130, 44].every(isBigEnough); // passed is false
passed = [12, 54, 18, 130, 44].every(isBigEnough); // passed is truehttp://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Global_Objects:Array:some
| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
var isBigEnough = function(element, index, array) {
return (element >= 10);
};
var passed = [2, 5, 8, 1, 4].some(isBigEnough); // passed is false
passed = [12, 5, 8, 1, 4].some(isBigEnough); // passed is truehttp://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Global_Objects:Array:filter
| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
var isBigEnough = function(element, index, array) {
return (element >= 10);
};
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough); // returns [12, 130, 44]http://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Global_Objects:Array:map
| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt); // roots is now [1, 2, 3]
// numbers is still [1, 4, 9]| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
var array = [2, 5, 9, 2];
var index = array.lastIndexOf(2); // index is 3
index = array.lastIndexOf(7); // index is -1
index = array.lastIndexOf(2, 3); // index is 3
index = array.lastIndexOf(2, 2); // index is 0
index = array.lastIndexOf(2, -2); // index is 0
index = array.lastIndexOf(2, -1); // index is 3http://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Global_Objects:Array:filter
| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
var lis = document.getElementsByTagName("li");
lis.forEach(function(element, index, array) {
console.log(element.nodeName.toLowerCase == "li") // alerts true
console.log(i) // Alerts current index
console.log(array) // alerts the elements container array
});http://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Global_Objects:Array:reduce
| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
Flatten an array of arrays:
var flattened = [[0,1], [2,3], [4,5]].reduce(function(a,b) {
return a.concat(b);
}, []);
// flattened is [0, 1, 2, 3, 4, 5]| element | the element to test against |
| index | (optional) A.K.A. "i", the current index in loop |
| array | (optional) element’s parent |
Flatten an array of arrays:
var flattened = [[0, 1], [2, 3], [4, 5]].reduceRight(function(a, b) {
return a.concat(b);
}, []);
// flattened is [4, 5, 2, 3, 0, 1]Allows you to extend the Flow namespace
// define closure
new Flow.Plugin({
name : "Foo", // You've defined "Flow.Foo"
version : "1.0.2 (fixes conflict with 'Soda.Grape')", // Versioning info
description : "Foo integrates Flow with 'Soda.Orange'.", // Brief description
constructor : { // The meat n' potatoes. Your Function/Object goes here
init : function(e) {
e = e.toUpperCase();
this.orange(e);
},
orange : function(e) {
this.flavor = e;
this.fizz();
},
fizz : function() {
alert("soda");
}
}.init("orange") // call constructor.init
}); // closure