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. SpringMVC-Mybatis整合和注解开发

    SpringMVC-Mybatis整合和注解开发SpringMVC-Mybatis整合整合的思路在mybatis和spring整合的基础上 添加springmvc.spring要管理springmvc ...

  2. 继 S-HR之代码创建临时表并插入数据 完整功能之员工职业信息变更报表

    目的示例1: 制作员工职业信息报表[S-HR系统的报表其实就是列表o.0,醉了] EcirrWithPP.js shr.defineClass("shr.custom.EcirrWithPP ...

  3. 微信支付开发 c#

    代码demo下载地址: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1

  4. Listview异步加载图片之优化篇

    在APP应用中,listview的异步加载图片方式能够带来很好的用户体验,同时也是考量程序性能的一个重要指标.关于listview的异步加载,网上其实很多示例了,中心思想都差不多,不过很多版本或是有b ...

  5. [USACO06JAN] 牛的舞会 The Cow Prom

    题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...

  6. Linux学习笔记记录(三)

    压缩: 例如将/etc 目录压缩为压缩包tar -cjvf  /aaa.tar.bz2  /etc           tar -czvf /aaa.tar.gz  /etc 解压: tar -xjv ...

  7. 牛客网NOIP赛前集训营 提高组 第5场 T2 旅游

    [题解] 我们可以发现不在最小生成树上的边一定不能多次经过,因为一条不在最小生成树上的边(u,v)的边权比最小生成树上(u,v)之间的路径更长,选择不在最小生成树上的边一定不划算. 我们还需要确定最小 ...

  8. PAT 1133 Splitting A Linked List

    Given a singly linked list, you are supposed to rearrange its elements so that all the negative valu ...

  9. Spring核心技术(三)——Spring的依赖及其注入(续)

    本文将继续前文,针对依赖注入的细节进行描述 依赖注入细节 如前文所述,开发者可以通过定义Bean的依赖的来引用其他的Bean或者是一些值的,Spring基于XML的配置元数据通过支持一些子元素< ...

  10. Garden of Eden

    Garden of Eden Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...