Chow's Blog


  • 首頁

  • 歸檔

  • 標籤

javascript创建Object

發表於 2016-01-16   |   分類於 javascript

使用Object构造函数和对象字面量都可以创建单个对象,缺点:使用一个借口创建很多对象,会产生很多重复性代码。

1.工厂模式

1
2
3
4
5
6
7
8
9
10
11
12
function createPerson(name, age, job){
var o = new Object();
o.name = name;
o.age = age;
o.job = job;
o.sayName = function(){
alert(name);
}
return o;
}
var person1 = createPerson('xiaoMing', 11, 'painter');
var person2 = createPerson('xiaomHong', 12, 'writter');

工厂模式创建多个相似对象,缺点:无法标识其类型

閱讀全文 »

Hello World

發表於 2016-01-09   |   分類於 javascript

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

閱讀全文 »
12
jellyChow

jellyChow

8 文章
1 分類
14 標籤
RSS
© 2016 jellyChow
由 Hexo 強力驅動
主題 - NexT.Muse