Skip to content

Instantly share code, notes, and snippets.

var sys = require('sys');
sys.puts("Top level");
sys.puts(" this === GLOBAL: " + (this === GLOBAL)); // false
sys.puts(" this === exports: " + (this === exports)); // true
var x = "1"; // local variable
sys.puts(" x === GLOBAL.x: " + (x === GLOBAL.x)); // false
/**
* Extend one object with the properties of any other object(s).
* @param obj The object to extend.
* @param args Additional arguments - the objects from which to copy properties.
* @return The object which was extended.
*/
var extend = (function(){
var
slice = Array.prototype.slice,
var
// path to something you want to download
path = "http://something/you/want/to/download",
// file you want to save it as
file = new java.io.File( "path/to/somewhere/local" ),
// create URL object and establish connection
url = new java.net.URL(path),
{"/*":"*/","//":"",/*"//"*/"/*/"://
"//"}
$.ajax({
url: "http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json",
dataType: "jsonp",
jsonp: "jsoncallback",
success: function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo('#images');
return i < 3;
});
}
$(function() {
var $ol = $('#blocked_list').find('ol').eq(0);
$.ajax({
url: 'http://api.twitter.com/1/blocks/blocking.json',
dataType: 'jsonp',
success: function(list) {
$ol.empty();
$.each(list, function(i,item){
$("<li><a><img /><span></span></a></li>")
.find("a")
// For each of the following code fragments:
// a. what does the code do?
// b. what did the author intend for it to do?
// c. how would you fix it?
// 1. list of links
var p = document.createElement('p');
for (var i=0; i<10; i++) {
var a = document.createElement('a');
a.innerHTML = "link " + i;