function cons(name,age){
this.name = name;
this.age = age;
this.getMes = function(){
console.log(`my name is ${this.name},this year ${this.age}`);
}
}
var mesge = new cons('will',21);
mesge.getMes();
function cons(name,age){
var obj = new Object();
obj.name = name;
obj.age = age;
obj.getMes = function(){
console.log(`my name is ${this.name},this year ${this.age}`);
}
return obj;
}
var mesge = cons('will',21);
mesge.getMes();
var cons = {
name: 'will',
age : 21,
getMes: function(){
console.log(`my name is ${this.name},this year ${this.age}`);
}
}
cons.getMes();
function cons(){
cons.prototype.name = "will";
cons.prototype.age = 21;
cons.prototype.getMes = function(){
console.log(`my name is ${this.name},this year ${this.age}`);
}
}
var mesge = new cons();
mesge.getMes();
var mesge1 = new cons();
mesge1.getMes();
console.log(mesge.sayName == mesge1.sayName);//true
function cons(name,age){
this.name = name;
this.age = age;
this.friends = ["arr","all"];
}
cons.prototype = {
getMes : function(){
console.log(`my name is ${this.name},this year ${this.age}`);
}
}
var mesge = new cons("will",21);
var mesge1 = new cons("jalo",21);
console.log(mesge.friends);
mesge.friends.push('wc'); //还可以操作数组哈O(∩_∩)O!
console.log(mesge.friends);
console.log(mesge1.friends);
mesge.getMes();
mesge1.getMes();
console.log(mesge.friends === mesge1.friends);
console.log(mesge.sayName === mesge1.sayName);
// 定义类
class Cons{
constructor(name,age){
this.name = name;
this.age = age;
}
getMes(){
console.log(`hello ${this.name} !`);
}
}
let mesge = new Cons('啦啦啦~',21);
mesge.getMes();
class Ctrn extends Cons{
constructor(name,anu){
super(name); //等同于super.constructor(x)
this.anu = anu;
}
ingo(){
console.log(`my name is ${this.name},this year ${this.anu}`);
}
}
let ster = new Ctrn('will',21);
ster.ingo();
ster.getMes();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有