1.1 Pattern

"theme of recurring events or objects… it can be a template or model which can be used to generate things" (http://en.wikipedia.org/wiki/Pattern).

• Design patterns - Elements of Reusable Object-Oriented Software.

• Coding patterns - JavaScript-specific patterns and good practices related to the unique features of the language, such as the various uses of functions.

• Antipatterns - An antipattern is not the same as a bug or a coding error; it's just a common approach that causes more problems than it solves.

1.2 JavaScript: Concepts

None-Objects: Primitive types - number, string, boolean, null, and undefined

1.2.1 Object- Oriented

Activation Object which is a global object which has attributes.

Object: a collection of named properties, a list of key-value pairs. Some properties could be functions.

Objects types

  1. Native

    Described in the ECMAScript standard

  2. Host

    Defined by the host environment (for example, the browser environment, e.g. window and all the DOM object) .

Objects can also be categorized by:

  1. Build-in (e.g. Array, Date).
  2. User-defined (e.g. var o ={}).

1.2.2 No Classes

There are no long parent-child inheritance chains.

There are no classes and object composition is what you do anyway.

1.2.3 Prototypes

prototype is an object (not a class or anything special) and every function has a prototype property.

1.2.4 Environment

  1. Browser patterns
  2. Practical applications of a pattern

1.3 ECMAScript 5

Strict mode - for backward compatible.

function my() {

"use strict";

// rest of the function...

}

This means the code in the function is executed in the strict subset of the language. For older browsers this is just a string not assigned to any variable, so it's not used, and yet it's not an error.

In this sense ES5 is a transitional version—developers are encouraged, but not forced, to write code that works in strict mode.

Principle on writing code under strict mode

• Ensuring the offered code samples will not raise errors in strict mode

• Avoiding and pointing out deprecated constructs such as arguments.callee

• Calling out ES3 patterns that have ES5 built-in equivalents such as Object.create()

1.4 JSLint - A kind of tool for grammar check.

1.5 The console - fire bug

JavaScript Patterns 1 Introduction的更多相关文章

  1. JavaScript Patterns 7.1 Singleton

    7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. Th ...

  2. JavaScript Patterns 6.7 Borrowing Methods

    Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...

  3. JavaScript Patterns 6.6 Mix-ins

    Loop through arguments and copy every property of every object passed to the function. And the resul ...

  4. JavaScript Patterns 6.5 Inheritance by Copying Properties

    Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...

  5. JavaScript Patterns 6.4 Prototypal Inheritance

    No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...

  6. JavaScript Patterns 6.3 Klass

    Commonalities • There’s a convention on how to name a method, which is to be considered the construc ...

  7. JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance

    // the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...

  8. JavaScript Patterns 6.1 Classical Versus Modern Inheritance Patterns

    In Java you could do something like: Person adam = new Person(); In JavaScript you would do: var ada ...

  9. JavaScript Patterns 5.9 method() Method

    Advantage Avoid re-created instance method to this inside of the constructor. method() implementatio ...

随机推荐

  1. sqlalchemy.exc.InvalidRequestError: Entity '<class 'model.TestCase'>' has no property 'project'

    原因: 修改表结构,但没有更新数据模型造成的 解决办法: 在sqlalchemy提供的表模型中增加project字段的描述信息 这次修改测试框架我有点想不起来,在测试代码中,是怎么通过sqlalche ...

  2. 梦想CAD控件网页版扩展数据

    随着基于CAD的应用软件飞速发展,经常需要保存一些与图形可视性无关的数据,即非图形参数.例如在绘制化验样图中包含品位数据.MxCAD定义一类新的参数——实体扩展数据.扩展数据与实体的可视性无关,而是用 ...

  3. java学习_5_24

    TreeMap底层是用红黑树实现的,源码如下: /** * A Red-Black tree based {@link NavigableMap} implementation. * The map ...

  4. 01JavaScript使用

    JavaScript使用 1.内容写入 HTML <P onmouseover="alert('欢迎您学习JavaScript!')">鼠标移过来</P> ...

  5. C++ CEF 浏览器中显示 Tooltip(标签中的 title 属性)

    在 Windows 中将 CEF 集成到 C++ 客户端以后,默认是无法显示 tooltip 的,比如图片标签中的 title 属性. 实现的方式其实很简单,按下面的步骤操作就可以: 创建一个文本文件 ...

  6. 类模板成员函数默认值问题:an out-of-line definition of a member of a class template cannot have default arguments

    template <typename T> class A { ); }; template<typename T> ) { /* */ } 对于类似上文代码,VS编译器会报 ...

  7. AWK简单使用方法

    1. 命令格式 gawk [OPTIONS] 'program' FILES.... program:'PATTERN{ACTION}' 一条awk命令中,PATTERN和ACTION,至少存在一个才 ...

  8. Linux命令学习(2): scp和rsync基本用法与断点续传

    版权声明:本文为博主原创文章,未经允许不得转载. 引子 在平常的工作中,我经常需要在远程服务器和本地之间传输文件. 以前我都使用scp命令,直到今天因为网络中断,scp出现了stalled. 因为上传 ...

  9. Python3.0科学计算学习之类

    类: Python中的类是一个抽象的概念,甚至比函数还要抽象.可以把它简单的看作是数据以及由存取.操作这些数据的方法所组成的一个集合.类是Python的核心概念,是面向对象编程的基础. 类有如下的优点 ...

  10. Spring核心技术(二)——Spring的依赖及其注入

    本文将继续前文,描述Spring IoC中的依赖处理. 依赖 一般情况下企业应用不会只有一个对象(或者是Spring Bean).甚至最简单的应用都要多个对象来协同工作来让终端用户看到一个完整的应用的 ...