我的网站开发技术经验总结 我的网站开发技术经验总结
首页

fangdown

我的网站开发技术经验总结
首页
  • 大前端

  • 基础

    • js

      • 你知道new操作符是如何实现的吗
      • 说说大文件上传的思路
      • 说说对闭包的理解及应用
      • 说说对单点登录sso的理解
      • 说说对防抖节流的理解
      • 说说对函数式编程的理解
      • 说说对内存泄漏的理解及触发场景
      • 说说对事件模型的理解
      • 说说对事件委托的理解及应用场景
      • 说说对原型及原型链的理解
        • 是什么
        • 怎么用
        • 总结
      • 说说对正则表达式的理解
      • 说说对BOM的理解及常见操作
      • 说说对Dom的理解及常见操作
      • 说说对JavaScript中事件循环的理解
      • 说说对js的执行上下文的理解
      • 说说对js中变量作用域的理解
      • 说说对js中继承的理解及实现方式
      • 说说对this关键字的理解
      • 说说你对 Immutable Data的理解?如何应用在React项目中
      • 说说如何判断数据类型
      • 说说如何判断一个元素在可视区域内
      • 说说如何实现函数缓存
      • 说说深浅拷贝的区别及实现
      • 说说什么是尾递归及其应用
      • 说说为什么0.1+0.2!==0.3
      • 说说下拉刷新,上拉加载的原理
      • 说说ajax的实现原理
      • 说说call-apply-bind的作用及区别
      • 说说js中本地存储有哪些方式及区别
      • 说说js中的类型转换机制
      • Javscript数组的常用方法有哪些?
      • Javscript字符串的常用方法有哪些?
    • css

    • ES6

  • 框架

  • 情商

  • 算法

  • 网络

  • 千锤百炼
  • 基础
  • js
fangdown
2021-08-30
目录

说说对原型及原型链的理解

# 是什么

  • 原型: proto 所有实例都有
  • 原型对象: prototype 构造函数拥有
function doSomething(){}
console.log( doSomething.prototype );
// 输出
{
    constructor: ƒ doSomething(),
    __proto__: {
        constructor: ƒ Object(),
        hasOwnProperty: ƒ hasOwnProperty(),
        isPrototypeOf: ƒ isPrototypeOf(),
        propertyIsEnumerable: ƒ propertyIsEnumerable(),
        toLocaleString: ƒ toLocaleString(),
        toString: ƒ toString(),
        valueOf: ƒ valueOf()
    }
}

# 怎么用

通过__proto__链接上一层的prototype

function Person(name) {
    this.name = name;
    this.age = 18;
    this.sayName = function() {
        console.log(this.name);
    }
}
// 第二步 创建实例
var person = new Person('person')

# 总结

  • 所有构造器都是函数对象 constructor
Object.__proto__ === Function.prototype

Object.prototype.__proto__ === null

Function.prototype.__proto__.__proto__ === null

Object.prototype.constructor.__proto__ === Function.prototype

  • 一切对象都继承Object对象,Object对象直接继承根对象null
  • 一切函数对象(包括Object)都继承自Function对象
  • Function对象的__proto__会指向自己的原型对象,最终还好是继承Object对象
var a = 1
// 构造函数Number-prototype
a.__proto__
Number {0, constructor: ƒ, toExponential: ƒ, toFixed: ƒ, toPrecision: ƒ, …}

// 构造函数 Object-prototype
a.__proto__.__proto__
{constructor: ƒ, __defineGetter__: ƒ, __defineSetter__: ƒ, hasOwnProperty: ƒ, __lookupGetter__: ƒ, …}constructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()__defineGetter__: ƒ __defineGetter__()__defineSetter__: ƒ __defineSetter__()__lookupGetter__: ƒ __lookupGetter__()__lookupSetter__: ƒ __lookupSetter__()get __proto__: ƒ __proto__()set __proto__: ƒ __proto__()

// null
a.__proto__.__proto__.__proto__
null
#js
上次更新: 2021/12/19, 18:05:42
说说对事件委托的理解及应用场景
说说对正则表达式的理解

← 说说对事件委托的理解及应用场景 说说对正则表达式的理解→

最近更新
01
多分支修复撞车的问题
05-01
02
如何成为架构师
01-23
03
服务器部署全过程
11-23
更多文章>
Theme by Vdoing | Copyright © 2019-2026 fangdown | 粤ICP备19079809号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式