首页 > Web开发 > 详细

js 创建对象模式

时间:2016-08-11 19:19:35      阅读:125      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!