Xah Web Dev Blog

HTML XML Entities (old page, new url)

Xah JavaScript tutorial, 2016-07 update

New version is out.

Buy Xah JavaScript Tutorial

Lots things has been updated. Several page have been re-written from scratch.

Most of the DOM scripting tutorial are re-written. And am working on more complete tutorial of DOM scripting.

Also working on ES6 features.

If you bought it already, you'll receive update.

if you don't have it it, give it a shot! Thanks.

The Sad State of Web Development

You see the Node.js philosophy is to take the worst fucking language ever designed and put it on the server.

The Sad State of Web Development By Drew Hamlett. @ https://medium.com/@wob/the-sad-state-of-web-development-1603a861d29f

history of CSS: The Languages Which Almost Became CSS

The Languages Which Almost Became CSS By Zack Bloom. @ https://eager.io/blog/the-languages-which-almost-were-css/

User Interface design: navigation panel, with scrollbar or no?

which you prefer?

side panel UI static-s side panel UI scrollbar-s
Fisrst picture: static panel, scroll with page. Second picture: with its own scrollbar.

vote on twitter at https://twitter.com/xah_lee/status/747375376616165376

or vote on Google Plus at https://plus.google.com/+XahLee/posts/MebjN6pPy5T


JavaScript Execution Order (rewrote. improved clarity)

JavaScript: Intro to Event-Based Programing (rewrote)

Reddit greed level up'd.

reddit screen block 2016-06-22
now, reading reddit without login will popup prompt and block view.
JavaScript quiz variable in array 2015-08-09
JavaScript Quiz: Variable in Array

(repost. on its own page)

html frameset 2016-06-21
HTML: Split Windows; Frameset

HTML Frameset is actually really a good UI. Unfortunately, it's killed by geeks for geek reasons.

Today, there's still not a workaround.

see it here: HTML: Split Windows; Frameset

the Java doc is still in html frameset, and it won't be going away anytime soon. Java Platform SE 8

(wow, so this means, browser will actually not deprecate it!)

JavaScript: Semicolon Rules (major rewrite, again. Now, explaining the new school of omitting semicolon)

actually, i now tend to think omitting semicolon is better. The rule is just far more simpler. It is also great saver on typing. Also, the semicolon in js is really a pain, because when editing code, refactoring, change between statement and expression, you have to constantly add / remove semicolon. But if you omit them at all times now, you don't have this problem anymore.

Web Design: Relative Date Sucks

the fashionable web design date “posted 834 days ago” is fscking annoying.

it began several years ago… around 2008 maybe.

say no to it.

i think, it'll eventually change back, to real dates.

〔➤see Web Design

2 nice JavaScript lib for plotting math functions

function-plot. runs on top of d3js. features interval arithmetics. https://github.com/maurizzzio/function-plot/

jsxgraph. geometer sketchpad like lib. http://jsxgraph.uni-bayreuth.de/wp/index.htmlhttps://github.com/jsxgraph/jsxgraph

JavaScript: Semicolon Rules. Much update.

there are 2 schools of thought. One, the Douglas Crockford classicist, recommend adding semicolon. The other, often younger, JavaScript coding hotshots in industry, recommend ommiting semicolon at all times.

JavaScript SVG set style problem

3 hours spent debugging this

svgElement.setAttribute("style", styleStr)


svgElement.style = styleStr;

The latter does not work on a 2011 old android tablet running 3 years old CyanogenMod running Google Chrome (too lazy to check version).

JavaScript Quiz. Array Splice Insert Without Nesting

// js quiz

// you have
function add () { return ["a","b"]; }
var tt = [1,2,3,4];

// you want
// [ 1, 'a', 'b', 2, 3, 4 ]

// modify tt, using splice. How?

for answer, see JavaScript: Array Splice Example

JavaScript: Array.prototype.reduce and reduceRight Example (new page. Basic example.)

JavaScript: Compute Date Range

Understand Atomic CSS in 1 Minute

JavaScript: Flatten Nested Array

see also JavaScript: Array How-To

JavaScript: Array.prototype.every Example

JavaScript: Test Equality of Objects

now, a function that compare 2 arbitrary objects, by deep dive.

JavaScript: Array Compare Equality (updated)

JavaScript: DOM Whitespace Nodes (added more example)

never, use delete to remove element in a array. Use Array.prototype.splice. It is the most general way to insert or remove slices at any position.

See JavaScript: Array Splice Example

JavaScript: Method Chaining and Function Composition

new version of JavaScript in Depth is out. Sent to previous buyers.

Buy Xah JavaScript Tutorial

if you bought it before, please leave a comment or review at Buy Xah JavaScript Tutorial. Hopefully positive. Thanks.

JavaScript: Replace All Children, createDocumentFragment

JavaScript: Randomize DOM List or Element Children

web bugs is now called web beacon.

that is, those 1 by 1 pixel image file used for tracking. (and many other techniques, now being standardized if not already)

Beacon spec https://www.w3.org/TR/beacon/

json syntax vs JavaScript syntax

json syntax isn't just what JavaScript accepts. For example:

see also JavaScript: JSON Methods

〔➤see Python: Read/Write to JSON

HTTP Protocol Tutorial (new)

CSS Random Gradient with JavaScript, at CSS Linear Gradient Tutorial

CSS Radial Gradient Tutorial (minor update)

JavaScript: Closure (minor update)

Web Design of Popular Sites: Serif or Sans Serif, Fixed Layout or Flow?

Meaning of Font Size. Standard Size for All Fonts?

best way to JavaScript: Get Current Script Tag

JavaScript: Clone Object. new tip.

DOM, List Attributes

in DOM, there's a strange attributes property, which return a list of attributes of a element.

use it like this

var hh = document.getElementsByTagName("a")[0];

var aa = hh.attributes;

// number of attributes

// first attribute

result object can be indexed by number (➢ for example: result[2]) or attribute name (➢ for example: result["src"]).


the returned object is a strange NamedNodeMap object. https://developer.mozilla.org/en-US/docs/Web/API/NamedNodeMap

see DOM Standard#interface-namednodemap

each element of NamedNodeMap is a strange Attr object. This Attr object went thru major DOM changes. https://developer.mozilla.org/en-US/docs/Web/API/Attr

I think if you really want a list of all attributes of a node, then there's no other way, use node.attributes. But otherwise, you can use

by the way, i said they are strange, because they are strange to me, and probably rarely used. I need to read the DOM spec. Now with whatwg's spec, it should be much easier to read. DOM Standard

〔➤see JavaScript: Basic DOM Methods

Disable Google Chrome Smooth Scrolling

latest Google Chrome v49 now has smooth scrolling. to disable it, goto chrome://flags/#disable-smooth-scrolling

JavaScript “undefined” trap

// JavaScript trap
var u = "2";
var o = {};
o[u.id] = 4;
console.log( o[u.id]); // works!!

lesson: JavaScript returns undefined in many situations, with no warning. (var with no init, non-existent property, out of bound array access, function with no return value, etc.) 〔➤see JavaScript: “undefined”

and JavaScript property names are strings. They are implicitly converted to string automatically. 〔➤see JavaScript: Property Names Are Strings

so, here, the u.id implicitly becomes "undefined", and now you basically have o = {"undefined":4};

WebSocket Tutorial

WebSocket is now mature, supported by all browsers.

Buy JavaScript in Depth. New version is out.

update sent to previous buyers. If you changed your email, let me know. email to xah@xahlee.org

Visual CSS. Now, there's side panel for easy navigation, for all pages.

JavaScript in Depth. Now each page has a side-panel, for easy navigation.

The Story of XML

ECMAScript 2015 Set Object's Parent

In ECMAScript 2015, a new function Object.setPrototypeOf(obj, parent) lets you set/change parent. (that is, effectively setting the [[prototype]] internal slot.) ECMAScript 2015 §Fundamental Objects#sec-object.setprototypeof

You should never change a object parent object. Because, for complex JavaScript implementation reasons, doing that is very slow. Instead, you should create a new object with the right parent. 〔➤see JavaScript: How to Create Object with Parent X?

see also JavaScript: Property Named “prototype”

JS+DOM: What Does Live Object Mean? (major update)

JavaScript: Event Delegation (updated. new code example, functional programing style)

JavaScript: Add / Remove Event Handler (updated)

JavaScript Execution Order (updated)

JavaScript: String Methods for Regex. Major update. Examples are on a page of their own.

the one html tag that summarize just how fk'd the web standards and fashions in past decade is: iframe

Past Articles by Date


Like what you read? Buy JavaScript in Depth.