美文网首页
高级-任务1

高级-任务1

作者: nicole914 | 来源:发表于2017-05-10 16:07 被阅读0次

问题1: OOP 指什么?有哪些特性

OOP: Object Oriented programming面向对象编程,是一种编程模式
OOP有三种特性:

  1. Encapsulation 封装
    封装描述了一种代码的组织结构形式,它把数据以及和它相关的行为打包起来。
  2. inheritance 继承
    继承给程序员提供了可复用的代码优势,子类通过继承,可以实现直接访问父类里的属性和方法等等,并在无需重新编写原来的类的情况下对这些功能进行扩展。
  3. Polymorphism 多态
    父类的通用行为可以被子类用更特殊的行为重写。

问题2: 如何通过构造函数的方式创建一个拥有属性和方法的对象?

function Person(name, gender) {
  this.name = name,
  this.gender = gender
}
Person.prototype.say = function() {
  console.log('The name is ' + this.name)
}
var person1 =  new Person('nicole', 'female')
person1.say()

问题3: prototype 是什么?有什么特性

prototype也是一个对象,是JS对象的原型
特性:
每一个JS对象都有原型
所有JS对象都从原型中继承属性和方法

问题4:画出如下代码的原型图

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('前端');

p1 ==> People.prototype ==> Object.prototype
p2 ==> People.prototype ==> Object.prototype


IMG_1162.JPG

问题5: 创建一个 Car 对象,拥有属性name、color、status;拥有方法run,stop,getStatus

function Car(name, color, status) {
  this.name = name
  this.color = color
  this.status = status
}
Car.prototype.run = function() {
  console.log(this.name + ' is running')
}
Car.prototype.stop = function() {
  console.log(this.name + ' is stopped')
}
Car.prototype.getStatus = function() {
  console.log(this.name + ': ' + this.status)
}
var car = new Car('benz', 'black', 'new')
car.run()
car.stop()
car.getStatus()

问题6: 创建一个 GoTop 对象,当 new 一个 GotTop 对象则会在页面上创建一个回到顶部的元素,点击页面滚动到顶部。拥有以下属性和方法

back to top

相关文章

  • 高级-任务1

    问题1: OOP 指什么?有哪些特性 OOP: Object Oriented programming面向对象编程...

  • 高级任务1

    1、OOP 指什么?有哪些特性 oop--->是object oriented programming的缩写,它是...

  • 高级任务1(主线任务):对象_原型

    问题1: OOP 指什么?有哪些特性 OOP是Object Oriented Programming(面向对象程序...

  • 高级-任务2

    this 相关问题 问题1: apply、call 、bind有什么作用,什么区别 apply和call的第一个参...

  • 高级-任务4

    题目1: 为什么要使用模块化? 模块的由来:嵌入网页的JS代码越来越庞大,越来越像桌面程序,需要一个团队去分工协作...

  • 高级-任务5

    题目1: 如何全局安装一个 node 应用? npm install -g 题目2: package.json 有...

  • 高级-任务3

    封装一个轮播组件 封装一个曝光加载组件 封装一个 Tab 组件 封装一个 Modal 组件

  • 高级 - 任务5

    课程任务 题目1: 如何全局安装一个 node 应用? 在命令行使用npm install -g xxx即可以全局...

  • 高级任务1---对象、原型

    问题1: OOP 指什么?有哪些特性 OOP(Object-Oriented Programming),是面向对象...

  • 20170928 周四 今日计划+回顾

    一、今日计划 学习任务:高级数据库 - Assignment 3,6h 学习任务:软件工程 - Lecture 1...

网友评论

      本文标题:高级-任务1

      本文链接:https://www.haomeiwen.com/subject/gdlhtxtx.html