js对象的创建和函数
创建对象
var obj1 = {
name:'老八',
age:'30'
}
console.log(obj1.age)
console.log(obj1.name) //输出name
console.log(obj1) //输出整个对象里的东西
工厂模式
let obj = new Object()
obj.name = name;
obj.age = age;
obj.sty = function(){
console.log('wdnmd')
}
return obj //返回到show
}
var l1 = show('我带你们打',15) //实参
var l2 = show('wdnmd',18)
console.log(l1)
console.log(l1.name)
console.log(l1.sty())
构造函数
function Per(name,age){
this.name = name
this.age = age
}
var p1 = new Per('老八',30)
console.log(p1)
原型方式+构造函数
function Per(name,age){
this.name = name
this.age = age
}
Per.prototype.say = function(){
console.log('1111')
}
var p1 = new Per('张三',15)
console.log(p1)
网友评论