Created
September 13, 2013 03:12
-
-
Save anonymous/6546419 to your computer and use it in GitHub Desktop.
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
http://blog.coolaj86.com/articles/intro-to-jshint-training-wheels-for-javascript.html | |
http://blog.coolaj86.com/articles/how-and-why-auto-executing-function.html | |
https://github.com/FuturesJS/forEachAsync | |
https://github.com/FuturesJS/FuturesJS/tree/v2.0/join | |
https://github.com/FuturesJS/FuturesJS/tree/v2.0/lateral | |
(function () { | |
"use strict"; | |
var net = require('net') | |
, client | |
; | |
client = net.connect({ port: 3030, host: "10.10.10.106" }); | |
client.on('connect', function () { | |
console.log('client connected'); | |
client.write('Hello\n'); | |
process.stdin.resume(); | |
}); | |
client.on('data', function (chunk) { | |
console.log(chunk.toString('utf8')); | |
}); | |
process.stdin.on('data', function (chunk) { | |
client.write(chunk); | |
}); | |
}()); | |
(function () { | |
"use strict"; | |
var net = require('net') | |
, client | |
, host = process.argv[2] || "127.0.0.1" | |
, port = process.argv[3] || 3030 | |
; | |
client = net.connect({ port: port, host: host }); | |
client.on('connect', function () { | |
console.log('client connected'); | |
client.write('Hello\n'); | |
}); | |
process.stdin.pipe(client); | |
client.pipe(process.stdin); | |
}()); | |
undefined | |
var obj = { }; | |
undefined | |
typeof obj; | |
"object" | |
obj; | |
Object {} | |
var arr = [ ]; | |
undefined | |
typeof arr; | |
"object" | |
Array.isArray(arr); | |
true | |
Array.isArray(obj); | |
false | |
clear() | |
undefined | |
obj = { "foo": "bar" }; | |
Object {foo: "bar"} | |
Object.keys(obj); | |
["foo"] | |
obj = { "foo": "bar", "baz": "corge" }; | |
Object {foo: "bar", baz: "corge"} | |
obj | |
Object {foo: "bar", baz: "corge"} | |
Object.keys(obj); | |
["foo", "baz"] | |
obj = { | |
"foo": "bar" | |
, "baz": "corge" | |
}; | |
Object {foo: "bar", baz: "corge"} | |
Object.keys(obj); | |
["foo", "baz"] | |
obj.grault; | |
undefined | |
obj.grault = "garply"; | |
"garply" | |
obj | |
Object {foo: "bar", baz: "corge", grault: "garply"} | |
console.log(obj); | |
Object {foo: "bar", baz: "corge", grault: "garply"} | |
undefined | |
console.log(JSON.stringify(obj)); | |
{"foo":"bar","baz":"corge","grault":"garply"} | |
undefined | |
var arr = [1, "2", "three", 4.2]; | |
undefined | |
arr | |
[1, "2", "three", 4.2] | |
obj["foo"]; | |
"bar" | |
obj.bar; | |
undefined | |
obj.foo; | |
"bar" | |
obj["foo"]; | |
obj.foo; | |
"bar" | |
var key = "foo"; | |
undefined | |
obj[key]; | |
"bar" | |
function printPairs(key) { | |
console.log(key, obj[key]); | |
} | |
undefined | |
Object.keys(obj).forEach(printPairs); | |
foo bar | |
baz corge | |
grault garply | |
undefined | |
obj["0"] = 42; | |
42 | |
Object.keys(obj).forEach(printPairs); | |
0 42 | |
foo bar | |
baz corge | |
grault garply | |
undefined | |
obj[0]; | |
42 | |
obj.0; | |
SyntaxError: Unexpected number | |
arr | |
[1, "2", "three", 4.2] | |
arr[0] | |
1 | |
Object.keys(arr).forEach(printPairs); | |
0 42 | |
1 undefined | |
2 undefined | |
3 undefined | |
undefined | |
arr[1]; | |
"2" | |
Object.keys(arr); | |
["0", "1", "2", "3" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment