过了一段时间,没写 原生的 javascript 的了,感觉天天在用框架写代码,框架写代码完全限定死了你所需要思考的东西,只是在处理一些业务逻辑,真正的代码

都感觉不会写了。 突然发现,框架用的不熟悉,原生的代码也忘得差不多了。感觉很难受,人生不能这样子度过!

  重新翻开《javascript 高级程序设计》, 回归到本原。工作上用框架写代码没错,业余时间的话就要自己多写一点原生的代码,或者说研究、模仿、直到自己设计一个

框架出来。

js 中的类, 对象, 类的静态变量,类的继承 。
function Scope(){
}

这样就是定义了一个类了。

-------------------------------------------------------------------

This figure again shows that every object has a prototype. Constructor function Foo also has its own __proto__ which is Function.prototype, and which in turn also references via its __proto__property again to the Object.prototype. Thus, repeat, Foo.prototype is just an explicit property of Foo which refers to the prototype of b and c objects.

var b = new Foo(20); var c = new Foo(30);

What are the differences between __proto__ and prototype properties?

up vote23down vote

Prototype VS. __proto__ VS. [[Prototype]]

When creating a function, a property object called prototype is being created automatically (you didn't create it yourself) and is being attached to the function object (the constructor).
Note: This new prototype object also points to, or has an internal-private link to, the native JavaScript Object.

Example:

function Foo () { this.name = 'John Doe'; } // Foo has an object property called prototype. // prototype was created automatically when we declared the function Foo. Foo.hasOwnProperty('prototype'); // true // Now, we can assign properties to to the prototype object without declaring it first. Foo.prototype.myName = function () { return 'My name is ' + this.name; }

If you will create a new object out of Foo using the new keyword, you basically creating (among other things) a new object that has an internal or private link to the function's prototype Foo we discussed earlier:

var b = new Foo(); b.[[Prototype]] === Foo.prototype // true

The private linkage to that function's object called [[Prototype]]. Many browsers are providing us with a public linkage instead that called __proto__!

To be more specific, __proto__ is actually a getter function that belong to the native JavaScript Object and returns the internal-private prototype linkage of whatever the this binding is (returns the [[Prototype]] of b):

b.__proto__ === Foo.prototype // true

It is worth noting that starting of ECMAScript5, you can also use the getPrototypeOf method to get the internal private linkage:

Object.getPrototypeOf(b) === b.__proto__ // true

NOTE: this answer doesn't intend to cover the whole process of creating new objects or new constructors, but to help better understand what is __proto__prototype and [[Prototype]] and how it works.

转载于:https://www.cnblogs.com/oxspirt/p/6517856.html

再说javascript 的__proto__ 和prototype 属性相关推荐

  1. JavaScript中__proto__与prototype的关系

    这里讨论下对象的内部原型(__proto__)和构造器的原型(prototype)的关系. 一.所有构造器/函数的__proto__都指向Function.prototype,它是一个空函数(Empt ...

  2. js(javascript)中__proto__和prototype解析

    为什么80%的码农都做不了架构师?>>>    __proto__是内部原型,prototype是构造器原型(构造器其实就是函数) 构造器的原型是一个对象 一.所有构造器/函数的__ ...

  3. JavaScript中__proto__、prototype和constructor的详细讲解【1】

    作为一名前端工程师,必须搞懂JS中的prototype.__proto__与constructor属性,相信很多初学者对这些属性存在许多困惑,容易把它们混淆,本文旨在帮助大家理清它们之间的关系并彻底搞 ...

  4. javascript函数上的prototype属性的理解

    2019独角兽企业重金招聘Python工程师标准>>> var fn = function(){}; console.debug(fn.prototype);  console.de ...

  5. js 的prototype 属性和用法,外加__proto__

    var ob = { };//超级简单的空对象 alert(JSON.stringify(ob.prototype));// undefined 能够引用prototype的东西绝对是函数,绝对是函数 ...

  6. Prototype属性说明

    1.prototype的定义 javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用. 每一个构造函数都有一个属 ...

  7. JS中函数的prototype属性和对象的__proto__属性

    <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8" ...

  8. javascript 原型属性(prototype 属性)与 实例属性(自身属性)

    讲到原型属性,prototype属性,实例属性,自身属性,首先我们要明白这四者之间的关系.我查了一些资料,原型属性又叫prototype属性,实例属性又叫自身属性.只是叫法不同.下面我要引用他人写的一 ...

  9. es6 prototype 属性和__proto__属性

    prototype 属性和__proto__属性 大多数浏览器的 ES5 实现之中,每一个对象都有__proto__属性,指向对应的构造函数的prototype属性.ES6 Class 作为构造函数的 ...

最新文章

  1. 2021年大数据ZooKeeper(五):ZooKeeper Java API操作
  2. 键盘码 ascii码
  3. 彻底关闭windows server 2008 IPv6
  4. linux mint输入法托盘,linux mint12安装ibus之后,语言栏不跟随光标和系统托盘输入法图标不能显示问题解决...
  5. 网站排名优化需掌握四项基本要素
  6. Python语言学习:Python随机生成那些事之随机生成使用方法、案例应用之详细攻略
  7. mysql判断表存在的sql语句_SQL 语句判断已知表是否存在_MySQL
  8. 大数据——Python数据爬取
  9. pycharm2019安装包以及汉化文件
  10. 台式计算机看网络电视,台式电脑无线投屏到电视
  11. 职工信息管理系统设计c语言,c语言之职工信息管理系统设计.doc
  12. 基于数据驱动的人脸识别课题研究
  13. 电脑键盘部分按键失灵_键盘按键失灵别担心 电脑达人教你几步解决方法
  14. MySQL快速学习入门
  15. 月薪两万的“土豪”师兄,加个微信吧!
  16. 护理和计算机哪个专业好,护理专业考研的就业前景和方向
  17. Vue 之 vue-seamless-scroll 实现简单自动无缝滚动,且添加对应点击事件的简单整理
  18. 【网络hcip】ospf学习 总结
  19. 信用评分卡 (part 5 of 7)
  20. 在前端培训班内该如何学习入门

热门文章

  1. 动态规划——01背包问题
  2. 程序设计竞赛(数组+多组测试)
  3. table { border-collapse:collapse; }
  4. 一文看懂Python(七)-----断言
  5. PyTorch基础(一)-----张量(Tensor)
  6. C语言再学习 -- 修改linux文件权限
  7. Java try和catch的使用
  8. 基于Android的ELF PLT/GOT符号重定向过程及ELF Hook实现(by 低端码农 2014.10.27)
  9. 计算机桌面颜色如何设置标准,电脑调整桌面颜色设置_电脑桌面颜色设置
  10. python怎么加图片_python怎么实现添加图片