Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ JavaScript prototype and prototype chain and project combat     - Install FFmpeg compiling from source in Mac OS X environment (Linux)

- Install minimize RHEL / CentOS 7 things to do (Linux)

- Configuring the remote Linux server SSH key authentication to automatically login in Mac OS X (Server)

- RPM package management tools under Linux (Linux)

- Compare Swift achieve rapid sorting and sorted Methods (Programming)

- VirtualBox virtual machine can not start to solve under Ubuntu (Linux)

- Linux system security knowledge (Linux)

- Linux Basics Tutorial: Combining awk delete data before the specified date hdfs (Linux)

- Java, boolean operators & =, | = ^ = use (Programming)

- Snapshot DataGuard (Database)

- Java 8 stream parsed into SQL (Programming)

- Use the TC flow control test under Linux (Linux)

- You need to know 12 Git High Command (Linux)

- CentOS install SVN server configuration and automatically synchronized to the Web directory (Server)

- Java NIO in the world (Programming)

- How to install Git client in Ubuntu (Linux)

- Ubuntu Apache2 setting, problem solving css, pictures, etc. can not be displayed (Server)

- Java is simple to read and write HDFS Demo (Programming)

- Linux / CentOS 7.0 installation and configuration under Tomcat 8.0 (Server)

- Linux excellent text editor (Markdown, LaTeX, MathJax) (Linux)

  JavaScript prototype and prototype chain and project combat
  Add Date : 2018-11-21      
  1. Basic Concepts
1.1 Prototype
Each function has a prototype (prototype) property that is a pointer to an object, and the object is to use all the forces of the class that contains the shared properties and methods.

No prototype way:

// Decimal point, tax rate

var decimalDigits = 2,

tax = 5;

function add (x, y) {

    return x + y;


function subtract (x, y) {

    return x - y;


// Alert (add (1, 3));

The first way:

var Calculator = function (decimalDigits, tax) {

    this.decimalDigits = decimalDigits;

    this.tax = tax;



Calculator.prototype = {

    add: function (x, y) {

        return x + y;



    subtract: function (x, y) {

        return x - y;



// Alert ((new Calculator ()) add (1, 3).);

The second way:

Calculator.prototype = function () {} ();

Calculator.prototype = function () {

    add = function (x, y) {

        return x + y;



    subtract = function (x, y) {

        return x - y;


    return {

        add: add,

        subtract: subtract


} ();


// Alert ((new Calculator ()) add (11, 3).);

Of course, we can also step declaration

var BaseCalculator = function () {

    // Declare a number of decimal places for each instance

    this.decimalDigits = 2;


// Prototype to BaseCalculator extended two object methods

BaseCalculator.prototype.add = function (x, y) {

    return x + y;



BaseCalculator.prototype.subtract = function (x, y) {

    return x - y;


1.2 prototype chain

ECMAScript describes the concept of the prototype chain, and the prototype chain as the main method of implementation inheritance. The basic idea is to use the prototype to make a reference type inherits from another type of reference properties and methods. A brief review of the relationship between the constructor and prototype instance: Each constructor function has a prototype object, the prototype object contains a pointer to a pointer to the constructor, and contains a pointer to the actual prototype object's internal pointer. So if we make a prototype object is equal to another instance of the type, what will happen then? Obviously, at this time the prototype object will contain a pointer to a pointer to another prototype, correspondingly, another prototype also includes a pointer to a pointer to another constructor. If the prototype is another instance of another type, the above relationship is still valid, so progressive layers, and constitutes an example of the prototype chain. This is the basic concept of the so-called prototype chain.

function SuperType () {

  this.property = true;


SuperType.prototype.getSuperValue = function () {

  return this.property;


function SubType () {

  this.subproperty = false;


SubType.prototype = newSuperType ();

SubType.prototype.getSubValue = function () {

  return this.subproperty;


var instance = new SubType ();

alert (instance.getSuperValue ()); // true

2. The project combat
Roadside assistance in the project, when the operator every step of the operation carried out, must be recorded in the log table inside the case, to allow administrators to clearly see the operation process every step of the operation, in order not to repeat the development, need to make a case record tools JS: CaseLogUtil.js

Wherein, when we want to call this method when instantiated directly CaseLog, call its methods to log.

Example: var test = new CaseLog ( "11", "content");

      test.log ();
- The Linux firewall is configured to use proxy (Linux)
- How to create a remote (Linux)
- Simple security measures to reinforce the Linux kernel (Linux)
- How to generate Linux, random password encryption or decryption (Linux)
- CentOS 7.0 Automatic installation CD-ROM production Comments (Linux)
- Use Tails 1.4 Linux system to protect the privacy and anonymity (Linux)
- Cobbler batch install Ubuntu / CentOS system (Linux)
- Linux under HAProxy + Keepalived dual-availability program (Server)
- Linux system package manager -RPM (Linux)
- Python 3.5 will support Async / Await Asynchronous Programming (Programming)
- ORA-12547: TNS: lost contact error Solution (Database)
- Use OpenSSL for RSA encryption and decryption (Linux)
- Switching Virtual Machine + Ubuntu graphical interface and terminal interface (Linux)
- Fedora 8 configured Heartbeat (Linux)
- Mind mapping software installed in CentOS 7 in XMind (Linux)
- Limit the use of the request being Nginx Flood attack (Linux)
- awk pattern matching (Programming)
- Using open source software to build XWiki Wiki system installed within the company (Linux)
- Ubuntu resolve sudo: source: command not found error (Linux)
- To install CentOS 6.5 on your hard drive under Windows 7 (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.