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. 执行join_paired_ends.py报错Cannot find fastq-join

    通过 conda 安装 qiime 1后,在执行join_paired_ends.py时报错: burrito.util.ApplicationNotFoundError: Cannot find f ...

  2. Linux常用命令——压缩与解压缩命令

    常用压缩格式:  .zip   .gz   .bz2   .tar.gz   .tar.bz2 1..zip格式压缩 zip 压缩文件名 源文件 压缩文件 zip -r 压缩文件名 源目录 压缩目录 ...

  3. 队列的头函数使用C++

    queue queue模板类的定义在<queue>头文件中. 与stack模板类很相似,queue模板类也需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选的 ...

  4. java解析从接口获取的json内容并写到excle(只写与标题匹配的值,并非把所有的接口返回值都写进去)

    需求:从接口中获取的一个json数组中有多个对象,每个对象中的值并非都需要,只需查出标题中的几项对应的值即可.且还需要按某个字段排序后依次写到excel 实现方法如下: package jansonD ...

  5. python之cookbook-day03

    第一章:数据结构和算法 1.3 保留最后 N 个元素 问题: 在迭代操作或其他操作的时候,怎样只保留最后有限几个元素的历史记录? 解决方案: 保留有限历史记录正是 collections.deque ...

  6. 电商架构设计-通过系统和业务拆分,遵循单一职责原则SRP,保障整个系统的可用性和稳定性

    个人观察 1.通过系统和业务拆分,遵循单一职责原则SRP,保障整个系统的可用性和稳定性. 2.单一职责原则SRP,真的很关键,广大程序员需要不断深入理解这个原则. 3.架构图是架构师的重要输出,通过图 ...

  7. angular中多个promise的合并处理

    all()方法 这个all()方法,可以把多个primise的数组合并成一个.当所有的promise执行成功后,会执行后面的回调.回调中的参数,是每个promise执行的结果.当批量的执行某些方法时, ...

  8. BZOJ 1565 Luogu P2805 [NOI2009]植物大战僵尸 (Tarjan判环、最小割)

    我: "立个flag 14点之前调完这题" 洛谷AC时间: 2019-06-24 14:00:16 实力打脸... 网络流板子从来写不对系列 题目链接: (BZOJ) https: ...

  9. Java基础学习总结(88)——线程创建与终止、互斥、通信、本地变量

    线程创建与终止 线程创建 Thread类与 Runnable 接口的关系 public interface Runnable {         public abstract void run(); ...

  10. 程序员节QWQ

    据$lc$说,今天是程序员节QWQ 过节啦QWQ