Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ JavaScript function part     - Use regular expressions to check whether the input box to enter a URL (Programming)

- Use LVM partition on Ubuntu and easily adjust the snapshot (Linux)

- OpenGL Superb Learning Notes - New Patterns (Programming)

- How to install Linux on a MacBook Pro Retina (Linux)

- Android Studio 1.0.2 set the memory size (Linux)

- Installation Flow N Play- interface stylized video player on Ubuntu (Linux)

- Linux and Windows Security Topics (Linux)

- Zorin OS: Linux novice most personal desktop system should be used (Linux)

- Live Wallpaper for Linux release adds dynamic background (Linux)

- Linux Shell debugging (Programming)

- Linux disk partition batch format mount script (Linux)

- CentOS6 MongoDB connection solution can not break 1000 (Database)

- Ubuntu firewall installation and configuration (Linux)

- Getting Started with Linux system to learn: How do I know which processes are running on the CPU core (Linux)

- DELL D630 Wireless LAN Driver Installation CentOS6 (Linux)

- Vim plugin installation YouCompleteMe (Linux)

- Lua regex (string function) (Programming)

- Android 4.2 compilation notes (Programming)

- Let CentOS perform PPPoE dial-up, ADSL can be used in a network environment! (Linux)

- Verify the character set on MyCAT (Database)

  JavaScript function part
  Add Date : 2018-11-21      

    JavaScript object literal notation allows only listed part of the object will be able to create the object. This is also the source of inspiration json. The so-called object literal {} is included in the plurality of sets of pairs.

var stooge = {
'First_name': 'jack',
'Last_name': 'ma'

    Value within the object can be used to take stooge [ 'first_name'] or stooge.first_name.

    Undefined values ​​from the object is illegal, such as stooge.name.me, a TypeError will be reported at this time. Solution is to use &&, stooge.name && stooge.name.me, this time to return undefined.

    Change the value of an object inside with stooge.first_name = 'mark' ;, if first_name does not exist, add a new property to the object.

    Used for navigating the object or for in.

for (var name in stooge) {
alert (stooge.name);

for in the disadvantage that traverse the object attributes are not ordered, sequential output to be used for

var names = [ 'first_name', 'last_name'];
for (var i = 0; i alert (stooge.names [i]);

    Remove object attribute with the delete. delete stooge.first_name


    Each object is connected to a prototype object, and you can inherit attributes from. Objects created by the literal are connected to the Object.prototype. Prototype connection only when retrieving a useful (this is useful, we need to know The change does not alter the value of the prototype), if you retrieve properties of an object, the object will not retrieve the prototype object it points until the final Object .prototype, finally did not return undefined.


    Function is the object, the object is the prototype chain end Object.prototype, the end of the function prototype chain is Function.prototype.

    Create function:

    Each function when created two additional properties, the context of a function, a function of the code is implemented (code for the function realization is also known as "Call" attribute when calling a function of time can be seen as calling this function call attribute).

var add = function (var a, var b) {
return a + b;

The above function is created with the literal. Created by literal function includes a connection to the connection context (the so-called closure).

    Function call:

    In addition to the called function parameters declared outside the reception will be receiving this and arguments parameters. this value depends on the call mode, a total of four call modes: method calls, function calls, constructor calls, apply call.

Method call:

var myObject = {
var value = 0;
add: function (i) {// here function is declared as a method
return this.value + i; // here this is myObject
myObject.add (2); // this is the function of the method call. By this method the calling function that belongs to the object itself.

Function call :( fallibility point here)

To illustrate this point, first following the instructions, and then look at an example. Here we should note that, during the time of this function call refers to the global windows, a direct impact on this problem is within the function when the function is called.

var i = 100;
var MyObject = {
    i: 10,
    out: function (value) {
        var inFun = function () {
            alert (value + this.i);
        inFun (); // this is a function call
MyObject.out (10); // here is the attribute (method) call

The above example inFun () call to the calling function, this refers to the windows, so the this.i = 100. The end result is 110.

To solve the above problem, you can use the following method:

var i = 100;
var MyObject = {
    i: 10,
    out: function (value) {
        var that = this; // here the method call came this first bound to the property that, when used under the above problem will not happen
        var inFun = function () {
            alert (value + that.i);
        inFun ();
MyObject.out (10);

Constructor calls:

I do not like a function call in this way, already familiar with java I think it looked very strange, would have been a function assigned to the variable on the strange. Here simply talk about.

var MyOb = function (ss) {
    var sta;
    this.sta = ss;
MyOb.prototype.fun = function () {
    return (this.sta);
var oo1 = new MyOb ( 'oo1'); // in the new time will be to call MyOb function is the key here, and this will create a function object is assigned oo1 behind, MyOb of this is the newly created object that is oo1
var oo2 = new MyOb ( 'oo2');
alert (oo1.fun ()); // returns oo1, because each sta are stored in the corresponding object
alert (oo2.fun ()); // returns oo2

apply call: This call allows us to manually transfer this.

var MyOb = function () {
    return (this.sta); // here, this is the app
var app = {
    sta: "it is ok!"
var res = MyOb.apply (app); // here manually assigned to this app
alert (res);

Here the function call does not complete, because it says the addition of this there is a parameter arguments. Line and take a look at what the role of this parameter.

var fun = function () {
    var i = 0;
    var sum = 0;
    for (i; i         sum + = arguments [i];
    return sum;
alert (fun (1,2,3,4,5));

As seen above, it is a parameter that contains a pass over the array (bottom just an array of classes).
- NAT and firewall under Linux (Linux)
- Linux NIC driver and version information (Linux)
- Android thread mechanism --AsyncTask (Programming)
- Use Oracle Data Guard to complete cross-platform database migration cases (Database)
- CentOS 7 version how to achieve the power to start the graphical interface (Linux)
- Puppet 3.x installed on Debian 7 (Server)
- According to the national position on how to block traffic in Linux (Server)
- Method under Linux GCC Compiler shared library function export control (Programming)
- Use Bash script write CVS version control (Server)
- VNC configuration detailed analysis under Linux (Linux)
- Oracle 11g partition maintenance (Nice) - Truncating And Partitions (Database)
- Linux delete duplicate files Artifact: dupeGuru (Linux)
- Android development environment to build under Fedora 13 (Linux)
- The Zabbix2.4.5 source compiler installation under Ubuntu 14.04 (Server)
- Redis performance test (Database)
- Install Krita 2.8 on Ubuntu 13.10 / 12.04 / 12.10 (Linux)
- Java Performance Tuning the proxy mode (Programming)
- Oracle 11g to create a second instance on Linux (Database)
- Linux LVM - File system extension (Linux)
- GNU Linux system variables (sysctl configuration commands) integrated use (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.