Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Depth understanding of JavaScript new mechanism     - Linux, Chrome browser font settings beautification (Linux)

- The Java utility, JavaMail (Programming)

- Teach you how to choose to install CentOS 6.5 installation package (Linux)

- High-performance open-source http accelerator Varnish introduce (Server)

- Via Twitter how open source library to be used anywhere Emoji emoticons (Linux)

- Teach you how to synchronize Microsoft OneDrive in Linux (Linux)

- MySQL query plan key_len know all (Database)

- Under Ubuntu 15.04 installation JDK8 (Linux)

- OpenvSwitch 2.1.2 shell script to start and stop (Linux)

- Linux system security settings (Linux)

- Linux, Apache Web site security settings (Linux)

- CentOS 6.x systems installation + NIC driver installation (Realtek PCIe GBE Family Controller for Linux) (Linux)

- Common Linux system performance monitoring command (Linux)

- iTerm - let your command line can also be colorful (Linux)

- iOS constants, variables, properties and characteristics (Programming)

- 10 Nginx safety tips (Linux)

- Linux foreground to background process switch (Linux)

- CentOS 5.5 install ntop (Linux)

- Linux ldconfig command (Linux)

- RealVNC Server 5.2.3 Installation and Configuration In Fedora (Server)

  Depth understanding of JavaScript new mechanism
  Add Date : 2018-11-21      
  We use JavaScript object, in addition to some of the browser's built-monomer object can be used directly, but it will be a new use.

1. The easiest way to get an Object object instance as follows

var obj = new Object ();

Description: At this point the new keyword did the most useful thing is that all methods inherited Object.prototype on this you can go to look at the list of methods es5 reference in the Object.prototype. This means that at this time the object obj can use all methods inherited it!

2. However, the constructor is new model allows us to have a deeper understanding!

function Person (name, age) {
    this.name = name;
    this.age = age;
    this.sayName = function () {
        console.log (this.name);
var person1 = new Person ( "wang", 23);
var person2 = new Person ( "jiang", 24);
var person3 = new Person; // When the time does not pass parameters


It is easy to know that each instance constructor alone get a property and methods. But this is how to achieve out of it?

new process, what happens?

1) Create an object.

2). The scope constructor assigns the new object (and therefore this points to a new object)

3) Execute the constructor code (add a property to a new object)

4) Return a new object

It is noteworthy that their inheritance is: person1 / person2 / person3 inherited from Person, and Person inherited from Object (all objects are inherited from Object)

If you understand the above things, meet new programming in some simple, basic enough.

Let's continue to continue to introduce some of the new topics

3. Module mode (Moudle mode), the following explains a simple block pattern examples


var Calculator = function (eq) {
    // Here you can declare private members
    var name = 2;
    var eqCtl = document.getElementById (eq);

    return {
        // Public members exposed
        name: name,
        add: function (x, y) {
            var val = x + y;
            eqCtl.innerHTML = val;
var c1 = new Calculator ( 'eq');
var c2 = new Calculator ( 'la');
c1.name = 3; // c1 the name of the property changes, but does not affect the name of the attribute c2
console.log (c1);
console.log (c2);
c1.add (2, 2);

It is worth noting that in this Calculator constructor returns an object!

Note: If the constructor returns an object (step 4) out so new objects will be returned objects covered. The results block pattern is c1 and c2 are objects returned from a copy properties and methods, independently of each other between them.

Inheritance also changed, c1 and c2 are directly inherited from Object.
- Getting Started Linux Shell Scripting (Programming)
- DB2 table space is redirected to restore the database combat (Database)
- MongoDB study notes - polymerization (Database)
- Linux using TCP-Wrapper Service Management (Linux)
- Ruby and Python simple comparison (Programming)
- Use XtraBackup to MySQL database online incremental backup and recovery (Database)
- ORA-00600: internal error code, arguments: [keltnfy-ldmInit], [46], [1], [], [], [], [], [] (Database)
- Awk include binding capacity larger than the specified size of all files directory (Linux)
- Oracle JDK installation under Ubuntu Linux (Linux)
- CentOS7 virtual machine starts appear Permission denied (Linux)
- Hardware Firewall Basics (Linux)
- Use matplotlib scientific drawing in Linux (Linux)
- Linux install Samba file sharing server (Server)
- KVM usb passthrough configuration (Linux)
- MariaDB 10.1 and MySQL 5.7 in general performance on commodity hardware (Database)
- Android Qemu GPS module (Programming)
- Java polymorphism and exception handling (Programming)
- vector C ++ sequence containers (Programming)
- to compile FFmpeg In Ubuntu (Linux)
- Linux centos rm directory does not prompt (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.