Basic JavaScript knowledge (JSON, Function object, prototype, and reference type), jsonfunction

Source: Internet
Author: User

Basic JavaScript knowledge (JSON, Function object, prototype, and reference type), jsonfunction


Concept: JavaScript Object Notation (JavaScript Object Notation) is a lightweight data exchange format.

Features: Easy For programmers to write and view; easy for computers to parse and generate

Data structure:Object format {key: value, key: value}

Array format [value, value]

Eg: var json = '{"": '''}' (internal double quotation marks, external single quotation marks)

* JSON-supports independent ". json" files; allows nesting

JSON format is supported in almost all mainstream development languages-the consensus of each syntax language is the string

Strings in JSON can only use double quotation marks.

* Supported data types: string; number; boolean; null; object; array

Convert JSON objects and strings

Convert to JSON object: JSON. parse (object) --- (Server => client), parse JSON string,

Convert to JSON string: JSON. stringify (string) ---- (client => server ),

2. Function object

Functions and Function objects:

The Function type is one of the reference types provided by JavaScript. An object of the Function type is created through the Function type, which is actually a [Function].

Var Object name = new Object (); --- create Object

Var function name =new Function( );   // function anonymous( ){}

[In JavaScript, all functions are Function objects]

Var Function name = new Function (parameter, Function body );

The last parameter in the brackets () is recognized as the function body. --- Not recommended


Purpose: To create an object (factory Mode)

Syntax structure:

Function constructor name (parameter) {this. property name = property value; ---- meaning of this-> refers to the object created this. method Name = function () {}} var object name = new constructor name ();

3. Prototype

In JavaScript, a Function is an object of the Function type that contains attributes and methods.

The Property (Prototype) already exists when the Function is defined. It is a predefined property of the Function object (that is, the Function). Its initial value is an empty object. The prototype of the function is not defined in JavaScript, so the prototype can be any type.

The prototype is used to save the shared attributes and methods of objects. The attributes and methods of the prototype do not affect the attributes and methods of functions.

2. prototype of the explicit prototype-Function

Used in a real development environment

2. Implicit prototype-Function _ proto __

Used for testing during development and cannot be used in real development environments

4. Reference Type

Data Type:

Number-define numbers by creating objects; String-define numbers by creating objects;

Boolean-defines a number by creating an object;

Date type

Purpose: Obtain the regular date + time

GetFullYear (): Get year; getMonth (): Get month; getDate (): Get date

GetTime (): the time and date from January 1, January 1, 1970 [Time Calculation Using millisecond value; timestamp (ID)]

Eg: the current time in the format of YYYY-MM-DD

Var date = new Date (); console. log (date. getFullYear () + 'Year' + date. getMonth () + 'month' + date. getDay () + 'day ');

Math type

Property: PI-circumference rate note: no object needs to be created

Method: Process numbers

Ceil (x): rounded up to add; floor (x): rounded down to give away; round (x): rounded down

Pow (x1, x2): n2 power random () of n1: generate a random number between 0 and 1

Eg: 0-100 random number console. log (Math. random () * 100 );

Console. log (Math. random () * 99 + 1 );

20% probability execution 1, 50% probability execution 2 if (num <= 0.2 ){

} Else {


Global Type

Global Objects: Global attributes (Infinity, NaN, undefined) and Global methods, which can be called anywhere in JavaScript.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.