JavaScript基于原型的继承的好例子 [英] Good Example of JavaScript's Prototype-Based Inheritance
问题描述
我用OOP语言编程已有10多年了,但我现在正在学习JavaScript,这是我第一次遇到基于原型的继承。通过学习优秀的代码,我倾向于学得最快。什么是正确使用原型继承的JavaScript应用程序(或库)的精心编写的示例?您能否(简要地)描述原型继承的使用方式/地点,所以我知道从哪里开始阅读?
I have been programming with OOP languages for over 10 years but I'm learning JavaScript now and it's the first time I've encountered prototype-based inheritance. I tend to learn fastest by studying good code. What's a well-written example of a JavaScript application (or library) that properly uses prototypal inheritance? And can you describe (briefly) how/where prototypal inheritance is used, so I know where to start reading?
推荐答案
道格拉斯·克罗克福德有一个关于 JavaScript Prototypal Inheritance 的精彩页面:
Douglas Crockford has a nice page on JavaScript Prototypal Inheritance:
五年前,我在JavaScript中写了经典继承。它表明JavaScript是一种无类别的原型语言,它具有足够的表达能力来模拟经典系统。从那时起,我的编程风格就已经发生了变化,就像任何优秀的程序员一样。我学会了完全接受原型主义,并将自己从经典模型的范围中解放出来。
Five years ago I wrote Classical Inheritance in JavaScript. It showed that JavaScript is a class-free, prototypal language, and that it has sufficient expressive power to simulate a classical system. My programming style has evolved since then, as any good programmer's should. I have learned to fully embrace prototypalism, and have liberated myself from the confines of the classical model.
Dean Edward的 Base.js , Mootools的类或 John Resig的简单继承工作原理是用JavaScript做经典继承的方法。
Dean Edward's Base.js, Mootools's Class or John Resig's Simple Inheritance works are ways to do classical inheritance in JavaScript.
这篇关于JavaScript基于原型的继承的好例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!