Skip to content

Instantly share code, notes, and snippets.

@AlyxRen
Created July 23, 2010 18:56
Show Gist options
  • Save AlyxRen/487874 to your computer and use it in GitHub Desktop.
Save AlyxRen/487874 to your computer and use it in GitHub Desktop.
Code for http://Rixi.us/
$.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');
(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('&amp;'),
//build the hash object
baz = (function(){
var x=-1, y=keyVals.length, oput = {}, key;
//loop through each KeyValue
while(++x&lt;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&amp;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));
//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"
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;
}
//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