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. axios方法封装

    axios方法封装 一般情况下,我们会用到的方法有:GET,POST,PUT,PATCH,封装方法如下:     五.封装后的方法的使用 1.在main.js文件里引用之前写好的文件,我的命名为htt ...

  2. ThinkPHP---thinkphp框架介绍

    目录: (1)简述: (2)下载: (3)文件结构: (4)部署: (5)细节问题: 主体: (1)简述 ThinkPHP诞生于2006年初,最初叫FSC.于2007年元旦更名为PHP,同时官网上线. ...

  3. 04Oracle Database 登陆

    Oracle Database 登陆 EM Express Login https://localhost:5500/em/login cmd sqlplus SQL/PLUS system/code ...

  4. PHP下载压缩包文件

    PHP 压缩文件需要用到 ZipArchive 类,Windows 环境需要打开 php_zip.dll扩展. 压缩文件 $zip = new ZipArchive(); // 打开一个zip文档,Z ...

  5. Extjs二级联动combo省城市

    Extjs二级联动 Extjs combox根据省查询城市 实现效果如上图所示, store层代码: Ext.define("ExtApp.store.TeacherProvince&quo ...

  6. 洛谷——P4296 [AHOI2007]密码箱

    P4296 [AHOI2007]密码箱 密码x大于等于0,且小于n,而x的平方除以n,得到的余数为1. 求这个密码,$1<=n<=2,000,000,000$ 暴力枚举,数据有点儿水$O( ...

  7. <SpringMvc>入门二 常用注解

    1.@RequestMapping @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME ...

  8. 随机数生成工具类(中文姓名,性别,Email,手机号,住址)

    public class RandomValueUtil { public static String base = "abcdefghijklmnopqrstuvwxyz012345678 ...

  9. 在mac上面运行cherrytree

    下载源码包 wget http://www.giuspen.com/software/cherrytree-0.38.4.tar.xz 解压 tar -xvf cherrytree-0.38.4.ta ...

  10. power coefficient calculation -- post processing

    input: unscaled moment of one bladeoutput: power coefficient of a 3-blades wind/tidal turbine matlab ...