JavaScript language Core (a)--prototype

Source: Internet
Author: User

In a static language like C + + strongly typed , the type determines the attributes and method of the value. A well-designed type cannot be changed during the running process

JavaScript weakly typed dynamic languages do not have a class that is "no type" in the language, and the type of the object is determined by the value in the run process.

    1. Methods not available in this type are borrowed from other types of methods
    2. Extending other types
The string type does not have a join method, but you can borrow methods from other types of array let str= ' Foo ';varres = Array.prototype.join.call (str, '-'));//output: ' F-o-o 'on the Number.prototype object, deploy a iterate method Number.prototype.iterate=function () {  varresult = [];  for(vari = 0; I <= This; i++) {Result.push (i); }  returnresult,};(8). Iterate ()//[0, 1, 2, 3, 4, 5, 6, 7, 8]

Values and types (value types and reference types)

In instanceof hasOwnProperty typeof

Basic 6 types: number, String, Object, null, undefined, Boolean.

Where array and function are sub-types of object.

All objects with the TypeOf return value are "object" with internal properties [[Class]],

Object.prototype.toString () to access

Object.prototype.toString.call (Item) = = = ' [Object Array] ';

C + + in the assignment and parameters of the transfer , through Value-copy and reference-copy, is determined by the syntax, such as display int& para;

And JavaScript is entirely determined by the type of the value.

There is a problem with the phrase ' JavaScript everything is object ', such as scalar-type values, not objects (no attributes and methods) var a = 2= ' Hahha ' and the corresponding C # implements everything Object http://www.cnblogs.com/mrcooldog/archive/ 2008/03/03/1088769.html

Scalar primitive Type values: String, numeric, Boolean, symbol they have a corresponding package type string () number () (similar to boxing and unboxing in other languages)

Compound Type Value-object: Numeric, function, custom object.

Let A = 3//  value-copy;  = [reference-copy//  ;

There are two types of JavaScript objects

    • Normal Object
    • Function object

Common objects include: New obj, {}, prototype

Functions object: Function () {}

All objects have the __proto__ property, which forms an inherited list that cannot be accessed in some browser environments. The default value for object __proto__ is

Object.prototype, while object.prototype.__proto__ = null means the end of the inheritance chain.

Only function objects have prototype objects.

Prototype Objectis actually Normal object: Console.log (F1.prototype)//"Object"Function.prototype, except that it is Function Object, but it's very special and it No prototype Property
var New OBJ (); Parse to: var o == obj.prototype;obj.call (o);

JavaScript language Core (a)--prototype

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: info-contact@alibabacloud.com 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.