JavaScript Patterns 1 Introduction
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
- Native
Described in the ECMAScript standard
- 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:
- Build-in (e.g. Array, Date).
- 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
- Browser patterns
- 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的更多相关文章
- 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 ...
- JavaScript Patterns 6.7 Borrowing Methods
Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...
- JavaScript Patterns 6.6 Mix-ins
Loop through arguments and copy every property of every object passed to the function. And the resul ...
- JavaScript Patterns 6.5 Inheritance by Copying Properties
Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...
- JavaScript Patterns 6.4 Prototypal Inheritance
No classes involved; Objects inherit from other objects. Use an empty temporary constructor function ...
- JavaScript Patterns 6.3 Klass
Commonalities • There’s a convention on how to name a method, which is to be considered the construc ...
- JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance
// the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...
- 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 ...
- JavaScript Patterns 5.9 method() Method
Advantage Avoid re-created instance method to this inside of the constructor. method() implementatio ...
随机推荐
- Android五大布局介绍&属性设置大全
前言 在进行Android开发中,常常需要用到各种布局来进行UI的绘制,今天我们就来讲下Android开发中最常用的五大布局介绍和相关属性的设置. 目录 Android五大布局介绍&属性设置. ...
- CAD从二进流加载数据(com接口VB语言)
主要用到函数说明: MxDrawXCustomFunction::ReadBinStreamEx 从二进流加载数据,详细说明如下: 参数 说明 IMxDrawBinStream* pBinStream ...
- Java基础——接口
一:接口,英文称作interface,在软件工程中,接口泛指供别人调用的方法或者函数. 在封装与接口中,private关键字封装了对象的内部成员.经过封装,产品隐藏了内部细节,只提供给用户接口(int ...
- java面试题链接
http://blog.csdn.net/jackfrued/article/details/17339393
- vuecli开发项目,文件打包后,appjs/vendorjs文件过大
项目上线后,浏览器第一次加载会特别特别慢,network中看到vendorjs文件1.9M,不慢才怪. echarts按需引入后,也有1.1M左右,由于对vue脚手架理解不深,自己扒了大量的文档,又测 ...
- buf.readUInt8()
buf.readUInt8(offset[, noAssert]) offset {Number} 0 <= offset <= buf.length - 1 noAssert {Bool ...
- 微信小程序开发过程中tabbar页面显示的相关问题及解决办法!
在微信小程序的开发过程中如果有使用过tabbar的同学,我相信一定会遇到一些困扰.为什么有些时候代码中明明已经在app.json里面增加了tabbar,可以页面中就是不显示呢?可不可以有些页面显示ta ...
- Set Map List Iterator
Set和Map类似,也是一组key的集合,但不存储value.由于key不能重复,所以,在Set中,没有重复的key. Map放没有顺序的键值对,所有键值对 — 参见 entrySet(),所有键 — ...
- 零基础到架构师 不花钱学JavaEE(基础篇)- 概述
Java简单来说是一门语言,Java能干什么? 网站:开发大,中,小型网站. 服务器端程序:企业级程序开发. APP:Android的APP基本使用Java开发. 云:Hadoop就是使用Java语言 ...
- NOIP2005 树网的核
题目描述 Description [问题描述]设 T=(V, E, W) 是一个无圈且连通的无向图(也称为无根树),每条边带有正整数的权,我们称T 为树网(treenetwork),其中V, E分别表 ...