Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第81题:JS设计模式-构造器模式 #81

Open
noxussj opened this issue Jun 18, 2020 · 2 comments
Open

第81题:JS设计模式-构造器模式 #81

noxussj opened this issue Jun 18, 2020 · 2 comments

Comments

@noxussj
Copy link
Owner

noxussj commented Jun 18, 2020

什么是构造器模式?

在面向对象编程中,构造器是一个当新建对象的内存被分配后,用来初始化该对象的一个特殊函数。在 JavaScript 中一切皆对象。 对象构造器是被用来创建特殊类型的对象的,首先它要准备使用的对象,其次在对象初次被创建时,通过接收参数,构造器要用来对成员的属性和方法进行赋值

栗子

function Car(model, year, miles) {
    this.model = model;
    this.year = year;
    this.miles = miles;

    this.toString = function() {
        return this.model + ' has done ' + this.miles + ' miles';
    };
}

var civic = new Car('Honda Civic', 2009, 20000);
var mondeo = new Car('Ford Mondeo', 2010, 5000);

console.log(civic.toString()); // Honda Civic has done 20000 miles
console.log(mondeo.toString()); // Ford Mondeo has done 5000 miles

总结:可以理解就是创建一个构造函数

@xiashanabc
Copy link

大佬讲一下v-for的key值作用呗

@noxussj
Copy link
Owner Author

noxussj commented Oct 19, 2021

大佬讲一下v-for的key值作用呗

在第64题有讲解哈,你可以看下是不是你需要的这种解释

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants