标签:obj info person fun 原型 创建对象 class new java
创建对象有以下几种:
var person = new Object(); person.name = "张三"; person.sex = "男"; console.info(person.name);
var person = { name : "张三" }
console.info(person.name);
var Person = function(name,sex){ this.name = name || "张三"; this.sex = sex || "男"; } console.info(new Person("张三").name);
function Person(){} Person.prototype.say = function(){ console.info("talk"); }
new Person().say();
function Person(name,sex){ this.name = name; this.sex = sex; this.say = function(){ console.info("实例:talk!"); } } Person.say = function(){ console.info("静态方法: talk!") } Person.prototype = { contructor : this, //原型链 say : function(){ console.info("原型:talk!"); } }
new Person().say();
pg: 执行顺序: 实例(this) 高于静态与原型
标签:obj info person fun 原型 创建对象 class new java
原文地址:https://www.cnblogs.com/fanruili/p/11405876.html