码迷,mamicode.com
首页 > Web开发 > 详细

js 创建对象模式

时间:2016-08-11 19:21:03      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

1. 概述

  可以创建一个函数, 在内部封装new。

 

function Student(props){
   this.name = props.name || ‘匿名‘;
   this.grade = props.grade || 1;    
}    

Student.prototype.hello = function(){
    alert(‘Hello, ‘+ this.name + ‘!‘);

}

function createStudent(props){
   return new Student(props || {});
}

 

js 创建对象模式

标签:

原文地址:http://www.cnblogs.com/rocky-fang/p/5762184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!