{"action":"opened","issue":{"url":"https://api.github.com/repos/raganyaYoung/blog/issues/1","labels_url":"https://api.github.com/repos/raganyaYoung/blog/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/raganyaYoung/blog/issues/1/comments","events_url":"https://api.github.com/repos/raganyaYoung/blog/issues/1/events","html_url":"https://github.com/raganyaYoung/blog/issues/1","id":123615348,"number":1,"title":"javascript创建对象","user":{"login":"raganyaYoung","id":16016489,"avatar_url":"https://avatars.githubusercontent.com/u/16016489?v=3","gravatar_id":"","url":"https://api.github.com/users/raganyaYoung","html_url":"https://github.com/raganyaYoung","followers_url":"https://api.github.com/users/raganyaYoung/followers","following_url":"https://api.github.com/users/raganyaYoung/following{/other_user}","gists_url":"https://api.github.com/users/raganyaYoung/gists{/gist_id}","starred_url":"https://api.github.com/users/raganyaYoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raganyaYoung/subscriptions","organizations_url":"https://api.github.com/users/raganyaYoung/orgs","repos_url":"https://api.github.com/users/raganyaYoung/repos","events_url":"https://api.github.com/users/raganyaYoung/events{/privacy}","received_events_url":"https://api.github.com/users/raganyaYoung/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-23T07:39:04Z","updated_at":"2015-12-23T07:39:04Z","closed_at":null,"body":"#javascript创建对象方式\r\n*工厂模式\r\n*构造函数模式\r\n*原型模式\r\n##工厂模式\r\n```javascript\r\nfunction createPerson(name,age){\r\n    var obj=new Object();\r\n    obj.name=name;\r\n    obj.age=age;\r\n    return obj;//一定要返回，否则打印undefined:undefined\r\n}\r\nvar person1=new createPerson('Young',18);\r\nconsole.log(person1.name+':'+person1.age);\r\n```\r\n优点：工厂模式可以解决创建多个相似对象\r\n缺点：没有解决对象识别问题（怎样确定一个对象的类型）ps:typeof\\instanceof\\...我还不会，要学习==!\r\n学习判断对象类型：http://www.cnblogs.com/flyjs/archive/2012/02/20/2360504.html\r\n##构造函数模式\r\n```javascript\r\nfunction Person(name,age){\r\n  this.name=name;\r\n  this.age=age;\r\n}\r\nvar person1=new Person('Young',18);\r\nconsole.log(person1.name+':'+person1.age);\r\n```\r\n"}}