Javascript does not have the concept of class. It is a prototyal language which means objects inherits directly from other projects.
The book introduces several ways to implement the inheritance.
1. Pseudoclassical
2. Prototypal
3. Functional
4. Parts
Below, I give an example of Functional inheritance, which I think is the most "javascript way".
function parent(s) {
var name = s.name;
var o={};
o.getName = function(){
return name;
};
return o;
}
var p=parent({name:"zhangruimin"});
console.log(p.getName());
function child(s) {
var title = s.title; //private field
var o=parent(s); //like call the parent constructor
var getParentName=o.getName;// store to implement override
var getTitle= function(){// private function
return title;
}
o.getName = function(){
return "In child: "+ getTitle()+getParentName();
};
return o;
}
var c=child({name:"zhangruimin", title:"MR."});
console.log(c.getName());
Here, we've got:
1. inheritance
2. private function and field
3. Call parent method
分享到:
相关推荐
Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative ...
创建窗体并管理多个窗体程序的范例源代码<br>WeatherGage: 一个自定义基类窗体的范例源代码<br>Inheritance: 从一个自定义父类窗体继承创建窗体的范例源代码<br><br>第14章<br>DrawRectangles: 使用触笔绘制矩形...
JavaScript The Good Parts Chapter 1. Good Parts Chapter 2. Grammar Chapter 3. Objects Chapter 4. Functions Chapter 5. Inheritance Chapter 6. Arrays Chapter 7. Regular Expressions Chapter 8. Methods ...
This brief book explains the advantages of the object model, inheritance, both classical and prototypical, and shows how these concepts can be implemented in JavaScript. It also shows how object ...
Part 1: The Basics -The Map Data Structure Part 1: The Basics -Type Synonyms Part 1: The Basics -Characters Part 1: The Basics -Character Categories Part 1: The Basics -Case-Folding Part 1: The Basics...
If you’re already well-versed in advanced JavaScript concepts such as closures, prototypal inheritance, the dynamic nature of this, and feature detection, you may want to skim this part for a ...
oriented<br>programming within C++: constructor semantics, temporary generation, support for encapsulation,<br>inheritance, and "the virtuals"-virtual functions and virtual inheritance. This book ...
However, there doesn’t seem to be any consensus in the community at large on a formal, rigorous, and abstract model of inheritance. This book proposes such a model, one that enjoys several ...
Zakas thoroughly explores JavaScript's object-oriented nature, revealing the language's unique implementation of inheritance and other key characteristics. You'll learn: –The difference between ...
Chapter 8: Inheritance Chapter 9: Handling Exceptions Chapter 10: Properties and Events Chapter 11: Interfaces Chapter 12: Manipulating Classes Chapter 13: Objects and Memory Part III Chapter 14: ...
The history of the EhLib library -------------------------------- Version 6.1 + A new component TDBVertGridEh - DataSet Grid with the ... <EhLib Archive> \ Demos \ Bin \ DBGridEh.LoadingStatus.Exe
JavaScript follows the prototypal inheritance pattern, unlike Java and C++ (which follow the inheritance pattern), there are some changes in writing data structures in JavaScript. The classical ...
The history of the EhLib library -------------------------------- Version 6.1 + A new component TDBVertGridEh - DataSet Grid with the ... <EhLib Archive> \ Demos \ Bin \ DBGridEh.LoadingStatus.Exe
NULL 博文链接:https://butterflymacro.iteye.com/blog/1271789
the new features added in ES6 Find out about ECMAScript 6’s Arrow functions, and make them your own Understand objects in Google Chrome developer tools and how to use Them Use a mix of prototypal ...
Like it or not, JavaScript is everywhere these days—from browser to server to mobile—and now you, too, need to learn the language or dive deeper than you have. This concise book guides you into and ...
Build sophisticated web applications by mastering the art of Object-Oriented Javascript About This Book Learn popular Object-Oriented programming (OOP) principles and design patterns to build robust ...
Part II: C++ Coding the Professional Way Chapter 7: Coding with Style Chapters 8 and 9: Classes and Objects Chapter 10: Discovering Inheritance Techniques Chapter 11: Writing Generic Code with ...
This new 7th edition of Pro C# 6.0 and the .NET 4.6 Platform has been completely revised and rewritten to reflect the latest changes to the C# language specification and new advances in the .NET ...
javax.persistence.Inheritance.class javax.persistence.InheritanceType.class javax.persistence.JoinColumn.class javax.persistence.JoinColumns.class javax.persistence.JoinTable.class javax.persistence....