过了一段时间,没写 原生的 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. cmd命令002

    cd..--> 返回上一级目录 cd\ --> 返回根目录"cd /d e:"--> 将当前盘符切换到e盘,"cd users/admin"- ...

  2. uva10570 Meeting with Aliens

    先证明把每次i放到i位置最后次数最少:感觉,可以,用归纳法? //在序列后再加一个相同的序列,就可以模拟用各个数字开头的情况了每个位置不对的只需要换一次54123 ,5固定->41235变成12 ...

  3. core 中使用 nlog

    引包 代码 public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory logFac) ...

  4. 把txt格式数据制作成xml数据

    txt格式数据: 代码: s1=""" <object> <name>{0}</name> <pose>Unspecifi ...

  5. dns config

    .: { forward . { force_tcp expire 50s health_check 50s } cache debug errors whoami log } Corefile .: ...

  6. css控制超出部分自动省略...

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

  7. windows环境下Robot Framework的安装步骤

    Robot Framework是由python编写的开源的用来做功能性测试的自动化测试框架.本文介绍Robot Framework在windows环境下的安装步骤. 安装python从python官网 ...

  8. Java应用异常状态监测

    阿里巴巴中间件技术专栏 老板最近分派了一个任务,说线上客户在部署应用的时候发生了系统级别的OOM,触发了OOM Killer杀掉了应用,让我们解决这个问题. 对于这个任务,我从如下几点开始调研.分析与 ...

  9. python基础知识06-函数基础和函数参数

    函数基础和函数参数 可迭代对象:序列类型 range . 1.函数的定义 def 函数名(参数): pass return 表达式 ,不能是赋值语句.不写默认返回None.用逗号隔开返回一个元组. 函 ...

  10. springMVC 文件上传 HTTP Status 400 – Bad Request

    可能原因是:multipartResolver没有配置正确 请看解决方案: <!--文件上传 id必须为multipartResolver,不然报错HTTP Status 400 – Bad R ...