JS中的面向对象

functon createPerson(name,sex,birthday)  
{  
  var oPerson = new Object;  
  oPerson.name =name;  
  oPerson.sex = sex;  
  oPerson.birthday = birthday;  
   
 oPerson.sayHi = function()  
 {  
    alert("Hi ! I am "+this.name);  
 }  
  return oPerson;  
}  
  
//那么我们多创建几个人的话,就可以  
var person1 = new createPerson('zs','boy','2001-02-03');  
var person2 = new createPerson('ls','boy','2001-02-04');  
person1.sayHi();  
person2.sayHi();  

最近看了一个项目源码,猛然喜欢上了js

posted @ 2019-02-14 10:25  Corey0606  阅读(90)  评论(0编辑  收藏  举报