function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype.sayName = function (){
console.log(this.name);
}
var p1 = new Person();
function People (name){
this.name = name;
this.sayName = function(){
console.log('my name is:' + this.name);
}
}
People.prototype.walk = function(){
console.log(this.name + ' is walking');
}
var p1 = new People('饥人谷');
var p2 = new People('前端');
function Car (name, color, status){
this.name = name;
this.color = color;
this.status = status;
}
Car.prototype.run = function() {
this.status = "running";
console.log(this.status);
}
Car.prototype.stop = function() {
this.status = "stop";
console.log(this.status);
}
Car.prototype.getStatus = function() {
console.log(this.status);
}
var p1 = new Car("宝马","black","run");
p1.run();
p1.stop();
p1.getStatus();
OOP 指什么?有哪些特性
Object-oriented programming的缩写,即面向对象程序设计,其中两个最重要的概念就是类和对象。类只是具备了某些功能和属性的抽象模型,类在实例化之后得到的实体就是对象。特性:
如何通过构造函数的方式创建一个拥有属性和方法的对象?
new一个对象发生了什么
this.__proto__指向构造函数的prototypeprototype 是什么?有什么特性
特性:
__proto__.__proto__=== 构造函数.prototype__proto__里面去找,如果还是没有找到,则从原型对象prototype里的proto中去寻找。画出如下代码的原型图
创建一个 Car 对象,拥有属性name、color、status;拥有方法run,stop,getStatus
创建一个 GoTop 对象,当 new 一个 GotTop 对象则会在页面上创建一个回到顶部的元素,点击页面滚动到顶部。拥有以下属性和方法
ct属性,GoTop 对应的 DOM 元素的容器target属性, GoTop 对应的 DOM 元素bindEvent方法, 用于绑定事件createNode方法, 用于在容器内创建节点代码
使用木桶布局实现一个图片墙
效果图

代码