日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

再说javascript 的__proto__ 和prototype 属性

發布時間:2025/3/15 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 再说javascript 的__proto__ 和prototype 属性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

過了一段時間,沒寫 原生的 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 属性的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。