Created
July 23, 2010 18:56
-
-
Save AlyxRen/487874 to your computer and use it in GitHub Desktop.
Code for http://Rixi.us/
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
$.get('url', function(data){ | |
//data is a JSON Array ['0','1','2'] | |
var end = $('<div>'); | |
end.append('<ul>') | |
//add the <ul> and traverse into it | |
.children(':last') | |
.append( | |
//make the anonymous function | |
(function(){ | |
var x = -1, | |
//data is accessible due to functional scoping | |
y=data.length, | |
// make a jquery <div> just to hold the appended Objects | |
oput=$('<div>'); | |
while(++x<y) { | |
oput.append('<li>'+data[x]+'</li>') | |
.children(':last') | |
.method1().method2(); | |
} | |
//return everything under the output </code><code class="javascript"> container | |
return oput.children(); | |
}()) | |
)//continue chaining; | |
},'json'); |
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
(function(loc){ | |
var _get = (function reload(){ | |
//If theres no GET Key Values, just return an empty Object; | |
if (!loc.search){ return {}; } | |
//remove the '?' | |
var list = loc.search.substr(1), | |
//Make an array of ['Key=Value',] | |
keyVals = keyvals.split('&'), | |
//build the hash object | |
baz = (function(){ | |
var x=-1, y=keyVals.length, oput = {}, key; | |
//loop through each KeyValue | |
while(++x<y) { | |
//split out key and value | |
key = keyVals[x].split('='); | |
//set key = value, or true if there's no value I.E. :: /i.html?simple&this=NotSimple | |
oput[key[0].toLowerCase()] = key[1] || true; | |
} | |
//in case you change the url without forcing a reset, you can reload the Hash Object | |
oput.Re = reload; | |
return oput; | |
}()); | |
return baz; | |
}()); | |
//Set the Global refrence to the Hash Object | |
window._GET = _get; | |
}(location)); |
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
//syntax | |
Object.create(Object prototype, Object objectDescriptors); | |
//Property descriptors | |
{ | |
value: '', //value to be set initially, any type | |
writable: true, //whether or not it may be modified | |
//or | |
get: function(){}, //return value is what will be returned when accessed | |
set: function(inp){}, //function called when property is set. | |
enumerable: true, //shows up on a for ... in loop if true | |
configurable: true //if false, is set to read-only(property is unwritable, and cannot be deleted, and this cannot be modified) | |
} | |
//use | |
var asd = Object.create(Object.prototype, { | |
'foo': { | |
value: "Bar", | |
writable: true, | |
enumerable: false | |
}, | |
'rix': { | |
get: function(){ | |
return this.foo+this.foo; | |
}, | |
set: function(inp){ | |
this.foo = inp; | |
}, | |
enumerable: true, | |
configurable: false | |
} | |
}); | |
asd.foo; //outputs "Bar", | |
asd.rix; //outputs "BarBar", | |
asd.rix = "Baz"; | |
asd.foo; //outputs "Baz", | |
asd.rix; //outputs "BazBaz", | |
for (var i in asd){ | |
console.log(i); | |
} //outputs only "rix", does not go over "foo" |
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
var foo = "true"; | |
foo; //outputs "true" | |
(true) && (foo = "I'm done!!"); | |
foo; //outputs "I'm done!!" | |
(true) || (foo = "fooBar"); | |
foo; //outputs "I'm done!!" | |
//function defaults:: | |
function fooBar(aab, baa){ | |
aab = aab || "foo"; | |
baa = baa || "Bar"; | |
return aab + baa; | |
} |
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
//Typecasting 101:: | |
// .toString() | |
406+''; //"406" | |
[100,42,"hello Dolly",86]+''; //"100,42,hello Dolly,86" | |
// parseInt(str, 10) | |
"406"*1; //406 | |
"604"-0; //604 | |
"1313"/1; //1313 | |
// Math.floor** | |
~~1.59678; //1 | |
~~6.954899; //6 | |
~~-2.649875; //-2** | |
// Boolean() | |
!!0; //false | |
!![]; //true | |
!!""; //false | |
!!34; //true | |
**:the only difference between ~~ and Math.floor is negative numbers, | |
Math.floor drops everything to the lowest interger side while | |
~~ pulls to the closest to 0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment