Josh Davis Explains JavaScript's Prototype Objects

Summary
Instead of classes, JavaScript uses prototypes as the basic building blocks of its object model. In a recent blog post, Josh Davis explains how prototypes compare to classes, and shows how to use the basic object-oriented techniques of inheritance and polymorphism in a prototypes-based language.

JavaScript is not only at the heart of popular Ajax frameworks, but is also one of the scripting languages that work well with Java on the server, and the next-genereration JavaScript is the foundation of ActionScript, the language behind Adobe's Flex framework. While JavaScript is an object-oriented language, instead of classes, it uses the concept of a prototype as the basic building-block of its object-model.


In a recent blog post, Prototype & Object Oriented JavaScript, Josh Davis explains that:



Prototype is a built-in JavaScript object which is a child of all objects and is used to create properties and methods for all instances of an object. You can use it on your JavaScript objects to create classes with externally defined methods...


You can also add methods to built-in JavaScript objects... You can also use prototype to create a class which extends another...



Davis shows several code examples of how to implement polymorphism and inheritance with prototypes.


What do you think of the prototype-based approach to OO, especially when compared with the class-based approaches used in Java, C++, or Ruby?


AddThis Social Bookmark Button

相关文档(Relevant Entries)
javascript常用日期验证
免费的Javascript日期输入及选择控件大杂烩!
JavaScript常用检测脚本
JS正则表达式的用法
JAVASCRIPT的常用技术(三)
JAVASCRIPT的常用技术(二)
JAVASCRIPT的常用技术(一)
自适应图片大小的窗口
WoW Powerleveling
Posted on May 5, 2007 6:52 PM | | | Comments (0) | | TrackBacks (0)

引用地址(TRACKBACKS)
 
TrackBack URL for this entry:
http://www.wujianrong.com/mt-tb.cgi/5282

发布评论(ADD YOUR COMMENTS)
 
感谢您参与评论;发表您的意见时请保持文章的相关性;不相关的或是单纯宣传的内容可能会被删掉。您的E-mail只是用来确认您发表的文章,不会出现在网页上。
Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

称呼(Name):      记住我的个人信息(Remember)
邮箱(Email):
网址(URL):
评论(Add your comments):

相关内容
广告计划