JS – Scope and Closures






One of the most fundamental paradigms of nearly all programming languages is the ability to store values in variables, and later retrieve or modify those values. In fact, the ability to store values and pull values out of variables is what gives a program state. Without such a concept, a program could perform some tasks, but they would be extremely limited and not terribly interesting.
But the inclusion of variables into our program begets the most interesting questions we will now address: where do those variables live? In other words, where are they stored? And, most important, how does our program find them when it needs them? These questions speak to the need for a well-defined set of rules for storing variables in some location, and for finding those variables at a later time. We’ll call that set of rules: 继续阅读: %s




自建NodeJS-聊天室(Socket.IO)






之前我写了一点,简单的关于node的了解,关于event,关于modulize代码,这里想分享一个聊天室的范例讲解,来演示一下,怎么建立一个Node项目,client 和 server 如何沟通,和如何使用event,还有很有用的socketIO module。
源代码可以在Github下载
在代码中,需要理解的地方我都标注的备注,所以这里就不在很细致的解释每行代码的意思了。
先来看看最后的成品:
在线连接
截图:
Screen Shot 2013-12-19 at 5.13.54 pm
基本上是一个最简单的在线聊天室:
– 支持多人同时聊天
– 支持自定义名字
– 支持创建聊天室 继续阅读: %s




Professional Javascript For Web Developers – Regular Expressions






Learning the Basics
. – Matches any character, except for line breaks if dotall is false.
//For example, /.n/ matches 'an' and 'on' in "nay, an apple is on the tree", but not 'nay'.
* – Matches 0 or more of the preceding character.
//For example, /bo*/ matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled", but nothing in "A goat grunted".
+ – Matches 1 or more of the preceding character.
//For example, /a+/ matches the 'a' in "candy" and all the a's in "caaaaaaandy".
? – Preceding character is optional. Matches 0 or 1 occurrence.
//For example, /e?le?/ matches the 'el' in "angel" and the 'le' in "angle" and also the 'l' in "oslo".
  If used immediately after any of the quantifiers *, +, ?, or {}, makes the quantifier non-greedy (matching the fewest possible characters), as opposed to the default, which is greedy (matching as many characters as possible). For example, applying /\d+/ to "123abc" matches "123". But applying /\d+?/ to that same string matches only the "1".
\d – Matches any single digit
//For example, /\d/ or /[0-9]/ matches '2' in "B2 is the suite number."
\w – Matches any word character (alphanumeric & underscore).
//For example, /\w/ matches 'a' in "apple," '5' in "$5.28," and '3' in "3D."
[XYZ] – Matches any single character from the character class.
[XYZ]+ – Matches one or more of any of the characters in the set.
$ – Matches the end of the string.
^ – Matches the beginning of a string.
[^a-z] – When inside of a character class, the ^ means NOT; in this case, match anything that is NOT a lowercase letter.

继续阅读: %s




Professional Javascript For Web Developers – Date Type






THE DATE TYPE

To create a date object, use the new operator along with the Date constructor

	var now = new Date();

继续阅读: %s




Professional Javascript For Web Developers – Array Type






THE ARRAY TYPE

After the Object type, the Array type is probably the most used in ECMAScript
ECMAScript arrays are ordered lists of data, but unlike in other languages, they can hold any type of data in each slot. This means that it’s possible to create an array that has a string in the first position, a number in the second, an object in the third, and so on.
Arrays can be created in two basic ways. The first is to use the Array constructor, as in this line:

	
	var colors = new Array();

继续阅读: %s




Professional Javascript For Web Developers – 复习笔记(Reference Types)






Reference Types

A reference value (object) is an instance of a specific reference type. In ECMAScript, reference types are structures used to group data and functionality together,Reference types are also sometimes called object definitions.
Even though reference types are similar to classes, the two concepts are not equivalent.
The Reference Type included:

1.The Object Type

(参考阅读:Javascript Object 的简单理解 )

2.The Function Type

(参考阅读:Javascript – Function 简单介绍

3.The Arrary Type
4.The Date Type
5.The RegExp Type
6.The Primitive Wrapper Types

继续阅读: %s




Node.JS Core explanation – 原理解释






最近看了一个很不错的演讲
继续阅读: %s




Professional Javascript For Web Developers – 复习笔记(Variables, Scope, and Memory)






variables -primitive & reference

ECMAScript variables may contain two different types of data: primitive values and reference values
Primitive values are simple atomic pieces of data, while reference values are objects that may be made up of multiple values.
The five primitive types were discussed in the previous chapter: Undefined, Null, Boolean, Number, and String.
variables are said to be accessed by value
Reference values are objects stored in memory
When you manipulate an object, you’re really working on a reference to that object rather than the actual object itself. For this reason, such values are said to be accessed by reference.reference value is assigned from one variable to another, the value stored on the variable object is also copied into the location for the new variable. 继续阅读: %s




Professional Javascript For Web Developers – 复习笔记






最近在重新复习javascript,推荐一个好书 :

Professional Javascript For Web Developers


下面是这本书的复习笔记: 继续阅读: %s




AngularJS App with an Node Express and mangoDB






最近做了很多研究,准备尝试用纯javascript作为主角写一个网页。
推荐一篇文章 -> An Introduction To Full-Stack JavaScript
一般来说,full stack Javascript的构造如下:

toptal-blog-image-large-opt

这里,我想实践的构造如下:

  • 数据库 : mango
  • client side: Angular JS & jQuery & bootstrap 3
  • server side: NodeJS express framework
  • server : AWS free tier 继续阅读: %s