Chinaunix首页 | 论坛 | 博客
  • 博客访问: 331019
  • 博文数量: 100
  • 博客积分: 2620
  • 博客等级: 少校
  • 技术积分: 920
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-16 02:50
文章分类

全部博文(100)

文章存档

2011年(5)

2010年(12)

2009年(83)

分类: 系统运维

2010-01-28 15:10:18

JavaScript for C & Python programmers

  • First posted: March 2006
  • Updated: July 2008 (linked to JSLint)
  • Update: April 2009 (better way to delete Array items)
  • Last update: January 2010 (Array example)

This is an introduction to JavaScript. There are plenty of these on the web, but most of them appear to be for non-programmers, teaching the building-blocks of programming as JavaScript uses them. And that's fine, because many people who have never programmed in their lives, find themselves needing a tiny bit of script for their web page, and need to start somewhere.

This article is designed to give much more in-depth information about JavaScript. It assumes a complete absence of knowledge about it, but it also assumes that you are already a competent programmer, preferably in a "C-like" language, and a smattering of Python will help too.

I'm going to cover everything I can think of short of the object model.

First of all, a common misconception to clear up: JavaScript is nothing to do with Java whatsoever. Nothing. Nada. Zilch. JS wasn't even originally called that (for that matter, nor was Java, but that's ). The Java- prefix is entirely there for marketing reasons that presumably made sense to some flake-nosed dot-com executive back in the 90s, squeezing their thighs together as they reviewed their stock options. Warning: This article contains whining on the subject of JS' "features". If you'd discovered these the hard way, you'd want to vent too...

JS is a dynamic language, with C-ish syntax for its basic flow control structures. Some of the more advanced datatypes look very Pythonesque, and indeed, so is its behaviour in quite a few respects.

In fact, it's a surprisingly powerful, expressive language, and could've been a very elegant bit of work.

However, it is not.

It is a dark festival of pain. Gotchas lurk in the darkness, biding their time. Brooding. Like bears: They .

JS is a thoroughly bastardised language, there's no getting away from that, and that goes double for the browser APIs.

In general, JS seems to follow the Principle of Most Surprise.

JS can be run stand-alone (eg ), or inside of special hosts (eg ), but most commonly it is embedded into web pages, by doing this:

html

Or:

html

阅读(1943) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~