过了一段时间,没写 原生的 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?

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.

再说javascript 的__proto__ 和prototype 属性的更多相关文章

  1. js原型和原型链,以及__proto__、prototype属性

    __proto__和prototype属性: 1.__proto__属性: 在JS里,万物皆对象(函数是对象.原型也是对象...).对象都具有属性__proto__,这个属性会指向该对象的原型. 2. ...

  2. JavaScript中__proto__与prototype的关系

    一.所有构造器/函数的__proto__都指向Function.prototype,它是一个空函数(Empty function) 1 2 3 4 5 6 7 8 9 Number.__proto__ ...

  3. JavaScript的__proto__、prototype和继承

    JavaScript也是可以“继承”的! 各位看官或是好奇,或是一知半解.什么是prototype,__proto__,constructor.哪种继承方式好.今天就在这交流交流. 什么是protot ...

  4. JavaScript中__proto__与prototype的关系(转)

    一.所有构造器/函数的__proto__都指向Function.prototype,它是一个空函数(Empty function) 1 2 3 4 5 6 7 8 9 Number.__proto__ ...

  5. Javascript深入__proto__和prototype的区别和联系

    有一个一个装逼的同事,写了一段代码 function a(){} a.__proto__.__proto__.__proto__ 然后问我,下面这个玩意a.__proto__.__proto__.__ ...

  6. 【JavaScript】__proto__和prototype的区别和联系【整理】

    var person={name:'ninja'}; person.prototype.sayName=function(){ return this.name; } Chrome运行结果: 提示找不 ...

  7. javascript中各类的prototype属性

    prototype 作用:获取调用对象的对象原型引用 应用:可以为某对象原型添加方法 例: function getMax() { var max = this[0]; for(var x=0; x& ...

  8. JavaScript 构造函数 prototype属性和_proto_和原型链 constructor属性 apply(),call()和bind() 关键字this

    1.构造函数: 通常构造函数首字母需要大写,主要是为了区别ECMAScript的其它函数.(高程三 P145) 构造函数与其他函数的唯一区别,就在于调用它们的方式不同.只要通过new来调用,任何函数都 ...

  9. javascript中构造器(函数)的__proto__与prototype初探

    背景:最近没什么需求,快要闲出屁了,所以重温了一下js的原型,结果大有收获,且偶然看到Snandy大神的<JavaScript中__proto__与prototype的关系> 这篇文章,感 ...

随机推荐

  1. tomcat 虚拟目录配置

    1.虚拟目录优点 原始 拷贝到webapps下,然后启动tomcat,就可以访问webapps下的项目.eclipse配置tomcat的原理也是这种方式. 虚拟目录 定位到eclipse工作目录下,实 ...

  2. 有n个整数,使其前面各数顺序向后移n-m个位置,最后m个数变成最前面的m个数

    题目:有n个整数,使其前面各数顺序向后移n-m个位置,最后m个数变成最前面的m个数 public class 第三十六题数组向后移m个位置 { public static void main(Stri ...

  3. OpenCV2:第三章 读取图像

    一.简介 将图像文件读入内存,可以用cv::imread()函数 二.读取图像 Mat imread(const string& filename,int flags=1); Mat: 如果读 ...

  4. 「 SPOJ GSS3 」 Can you answer these queries III

    # 题目大意 GSS3 - Can you answer these queries III 需要你维护一种数据结构,支持两种操作: 单点修改 求一个区间的最大子段和 # 解题思路 一个区间的最大子段 ...

  5. 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x003E2000).错误

    这个错误是“栈溢出”,每个线程的栈空间默认是1MB,局部变量(非静态)都在栈中分配,当使用的局部变量所需空间过多时,就会溢出.你检查一下程序,看看哪些函数中定义了大数组,把大数组改成用new分配,函数 ...

  6. 9. InnoDB通用表空间

    9. InnoDB通用表空间 通用表空间是InnoDB 使用CREATE TABLESPACE语法创建的共享表空间.本节中的以下主题描述了常规表空间功能和功能: 通用表空间功能 创建通用表空间 将表添 ...

  7. POJ 1252 Euro Efficiency(最短路 完全背包)

    题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...

  8. 算法导论 第十章 基本数据类型 & 第十一章 散列表(python)

    更多的理论细节可以用<数据结构>严蔚敏 看几遍,数据结构很重要是实现算法的很大一部分 下面主要谈谈python怎么实现 10.1 栈和队列 栈:后进先出LIFO 队列:先进先出FIFO p ...

  9. cf839c Journey

    大水题 #include <iostream> #include <cstdio> using namespace std; int n, du[100005], hea[10 ...

  10. navicat不同数据库数据传输

    复制fo的t_fo_account表结构和数据到base库 结果