<script type="text/javascript">
function Person(){
this.name=‘li4‘
this.age=20
this.eat=function(){console.log(‘eating ...‘)}
this.sing=function(){console.log(‘sing ...‘)}
}
var p1=new Person()
console.log(‘my name is ‘+p1.name+‘, i am ‘+p1.age)
p1.eat()
p1.sing()
//设计模式:简单的链式编程,
//调用return this
function Man(){
this.name=‘w5‘
this.age=24
this.eat=function(){console.log(‘包子、油条 ...‘);return this;}
this.work=function(){console.log(‘coding ...‘);return this;}
this.sleep=function(){console.log(‘z Z Z...‘);return this;}
}
var m=new Man()
m.eat().work().sleep()
</script>原文:http://f1yinsky.blog.51cto.com/12568071/1954284