Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Depth understanding of JavaScript new mechanism     - VirtualBox virtual machine can not start to solve under Ubuntu (Linux)

- Boost notes --Thread - problems encountered in the initial use on Ubuntu (Programming)

- CentOS7 boot systemd introduction and use of management (Linux)

- Deploy Mono 4 and Jexus 5.6 on CentOS7 (Server)

- CentOS 6 adds disk quota limit (Linux)

- Basic Java JNI (Programming)

- Text editing and viewing text Linux command (Linux)

- Android and OpenCV2.4.4 build an image processing framework (2013 edition) (Linux)

- Towards Docker (Server)

- Oracle 12C RAC optimizer_adaptive_features cause of data into overtime (Database)

- Ubuntu installation 2.10.x version of Scala (Linux)

- Installing Linux and Windows 10 dual system (Linux)

- Linux Services Comments (Linux)

- Jump table (skiplist) of code (Programming)

- Java class loading order (Programming)

- RM Environment Database RMAN Backup Strategy Formulation (Database)

- Use XtraBackup be physical standby database MySQL (Database)

- How to implement Linux host Telnet SSH password Free (Server)

- Oracle study notes view (Database)

- After Oracle 11g dataguard failover rebuild the archive logs are not applied to be NO problem (Database)

 
         
  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.
     
         
       
         
  More:      
 
- Kali Linux 2.0 U disk installation errors Your installation cd-rom could not be mounted (Linux)
- Debian 7.6 install Nvidia graphics driver (Linux)
- Upgrading Oracle 11.2.0.1 to 11.2.0.3 (Database)
- C ++ sequence containers basics summary (Programming)
- Spring Data MongoDB combat (Database)
- Ubuntu Control Panel to resolve network-manager icon display issue (Linux)
- PostgreSQL-- run Supervisord on Docker in Ubuntu (Database)
- Using Vagrant create cross-platform development environment (Linux)
- Node.js development environment deployment (Server)
- Through eight skills to let you become a super Linux end-user (Linux)
- Connect to the Oracle Database Help class (Database)
- To modify the existing user ID and comments GPG key (Linux)
- Using Linux strace command trace / debug a program commonly used options (Linux)
- How to configure SNMPv3 on Ubuntu, CentOS and Cisco systems (Linux)
- Python substring format (Programming)
- You need to know 12 Git High Command (Linux)
- How to turn Java String into Date (Programming)
- ActionContext and ServletActionContext Summary (Programming)
- OpenGL Programming Guide (8th edition of the original book) - compute shader (Programming)
- Android first line of code study notes (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.