Xah Web Dev Blog Archive 2013-12

JS: RegExp Syntax (first version)

split into 2 pages.

web hosting service with virtual machine

woot! just activated my digitalocean account. It's a web hosting service using virtual machines. Meaning, you have a whole linux box to yourself, as a dedicated box, with root access. So, you can do anything you want. Ruby, Rails, ngixn, Node.js, anything, or just play with it. They run it on solid state drive.


JS: Random Range Function (updated)

♥ JavaScript, Node.js, socket.io ♥

thanks to friends on g+, discovered Socket.io

Socket.IO is a JavaScript library for realtime web applications. It has two parts: a client-side library that runs in the browser, and a server-side library for node.js. Both components have a nearly identical API. Like node.js, it is event-driven.

Socket.IO primarily uses the WebSocket protocol, but if needed can fallback on multiple other methods, such as Adobe Flash sockets, JSONP polling, and AJAX long polling,[2] while providing the same interface. Although it can be used as simply a wrapper for WebSocket, it provides many more features, including broadcasting to multiple sockets, storing data associated with each client, and asynchronous I/O.

It can be installed with the npm (node packaged modules) tool.[3]

if you have Node.js's npm installed, npm install socket.io

JavaScript, Node.js, am in heaven. Screw perl, python.

love the Ryan Dahl guy. Today's work, annotated the whole thing. His video is the best intro to node.js. Node.js Video Tutorial by Ryan Dahl, with Annotation

my copy of the node.js doc. New is the left side persistent list of node objects. Node.js v0.11.10-pre Manual and Documentation

JS: Default Charset/Encoding (updated)

Variable assignment returns a value.

// variable assignment returns a value
var xx;
console.log(xx = 3);            // 3

So, variable assignment can be chained.

var xx;
var yy;

console.log(xx = yy = 3);       // 3
console.log(xx);                // 3
console.log(yy);                // 3

JavaScript Tutorial by Example

JavaScript. Multiple variables can be declared on the same line, separated by comma var name1, name2, name3 …;

// declare variable, use 「var」
var x;
var y;

// multiple variables can be declared on the same line, separated by comma
var a, b, c;

Multiple variables can be declared and assigned at the same time.

// declare variable and assign
var x = 4;

// declare variable and assign multiple variables
var a = 1, b = 2, c = 3;

When a variable is declared but not assigned, the default value is undefined.

When a variable is not declared nor assigned, and you try to access it, you get ReferenceError.

var x;
console.log(x); // prints 「undefined」
console.log(y); // ReferenceError: y is not defined

Several tutorials on web server and networking. Btw, don't use Apache. Apache is dinosaur. Use nginx and node.js.

JS: var Name Scope (updated)

Search Unicode Characters

major update on unicode search. You can search by name, codepoint (decimal or hexadecimal) or paste in Unicode characters. Search is now real-time. Result shows as you type. For example, try to find unicode related to christmas. 🎄 🎅.

xah unicode search 2013
Unicode Search

JS: Property Attributes (updated)

web UI/UX design is like fashion industry. Each year, grave words are given about the kick-ass-ness of certain design, but after few years, it's all forgotten.

whoever moved the reload ⟳ button into the URL bar is a idiot. Was it Apple Safari who started this?

JS: Function Call, Apply, Bind

JS: What's Strict Mode and How to Determine Strict Mode? (updated)

JS: Operator “new” (updated)

JS: Create Object (major update)

JS: Prototype and Inheritance (more update)

JS: Property Dot Notation / Bracket Notation (updated)

added a section about using function scope as namespace. JS: var Name Scope

JS: Closure in Javascript

JS: var/function Order

JS: Basic DOM Methods (major update)

JavaScript Encode URL, Escape String (major update)

JS: Array vs NodeList vs HTMLCollection (major update)

updated with new syntax coloring, a formal language approach to computer language documentation.

JS: Basic DOM Methods (updated with new syntax coloring)

do you understand the lang well before you use frameworks?

JavaScript Example of Functional Programing: Normalize Vector

// JavaScript. By William James. Modified by Xah Lee
function normalize( vec ) {
var div = Math.sqrt(vec.map(function(x) {return x*x}).reduce(function(a,b) {return a+b}));
return vec.map(function(x) {return x/div});

// [ 0.3234983196103152, 0.43133109281375365, 0.539163866017192, 0.6469966392206304 ]

see Vector Normalize Function in Mathematica, APL, Haskell, Ruby, Python, Perl, Lisp, JavaScript, Java, …

JavaScript, example of array splice, 3 arguments form

// example of array splice, 3 arguments form
var uu = [0,1,2,3,4,5];
var rs = uu.splice(2,3, "a");   // start at index 2, removed 3 items, add "a"
console.log(uu);                // [ 0, 1, 'a', 5 ] the new value
console.log(rs);                // [ 2, 3, 4 ] removed items

〔►see JS: Array.prototype.splice

Intro to Event in GUI Programing (updated)

How to Create and Update a Website Logo (Favicon) (minor update)

Like what you read? Buy JavaScript in Depth