JS Basic Knowledge Point Collection

Source: Internet
Author: User

JS Basic knowledge Point Collection JS common base types
 function show(x) {Console. log (typeof(x));//undefined        Console. log (typeof(Ten));// number        Console. log (typeof(' abc '));//String        Console. log (typeof(true));//Boolean        Console. log (typeof([]));//Object        Console. log (typeof( function () {        }));//function        Console. log (typeof([1,' A ',true]));//object        Console. log (typeof({a:TenB: -}));//object        Console. log (typeof(NULL));//object        Console. log (typeof(New  Number(Ten)));//object} show ();

Value type: Undefined, number, String, Boolean
Reference types: Functions, arrays, objects, null (all reference types are objects, objects are collections of properties)

JS Prototype and prototype chain
 function Fn() {} Fn.prototype.name =' Wang Fu '; Fn.prototype.getYear = function () {return 1988; };varfn =NewFn ();Console. log (Fn.name);Console. log (Fn.getyear ());

FN is fnnew out of the object, FN.Proto = = = Fn.prototype

JS prototype chain
 function  foo   ()   {} var  f1 = new  Foo (); //f1.a = ten;  Foo.prototype.a = 100 ; foo.prototype.b = 200 ; console . log (f1.a); //100  console . log (f1.b); //200  

When the F1 is assigned a value

    console.log(f1.a);//10    console.log(f1.b);//200

Prototype chain:访问一个对象的属性时,先在基本属性中查找,如果没有,再沿着__proto__这条链向上找,这就是原型链

JS prototype chain inheritance
A = {a: function () {Console. log (' A '); }} b= {B: function () {Console. log (' B '); }} a.a ();//aB.B ();//b    Object. setprototypeof (A, b);//Give the prototype of B to aA.B ();//b
JS context

提到js的上下文先说下this关键字
The value of this in the function is determined when the function is actually called and the function definition cannot be determined.

Scenario 1: Constructors

    function A() { This. A =' A '; This. Hello = function () {Console. log ( This. a);//a}Console. log ( This);//{a: "A"}}varA =NewA (); A.hello ();

If the function is used as a constructor, then this represents the object it is about to be new.

Scenario 2: Function as a property of an object
Console.log (THIS.A);//a

Scenario 3: Function calls

with call or apply
  var B = {        ‘b‘    }    varfunction () {        console.log(this.b);    }    A.call(B);//b

When a function is called by call and apply, the value of this takes the value of the passed-in object.

Scenario 4: Function global & Call common functions
In the global environment and normal function calls, it is the window

JS Basic Knowledge Point Collection

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.