Proficient in Javascript Reading Notes 1

Source: Internet
Author: User

Javascript proficiency

Chap 1

1. Use a namespace to protect your database.

YAHOO.util.Event.addListner(...);

Chap 2

2. Reference

Multiple variables can point to the same object. A reference can only point to a specific object, rather than another reference. Multi-layer references are not allowed.

However, when the string connection operation is executed, the result is always a New String object instead of the modified version of the source string.

Eg1.

var object=new Object();var objRef=obj;obj.oneProperty=true;alert(obj.oneProperty === objRef.oneProperty);

Eg2.

var items=new Array("one","two","three");var itemsRef=items;items=new Array("new","Array");alert(items!=itemsRef);

Eg3.

var item="test";var itemRef=item;item+="ing";alert(item!=itemRef);

 

3. Determine the input parameter type

If no parameter is provided, the type must be undefined.

if( typeof msg == 'undefined') {...}

1) typeof statement

This is a good solution when the variable is not of the object or array type. However, for a custom object, for example, a user cannot use this method for type check, because it only returns the object.

2) constructor

This property references the function originally used to construct the object.

// check numberif(num.constructor == String)      num=parseInt(num); //check arrayif(str.constructor == Array)      str=str.join(',');

3) Comparison between typeof and constructor

Variable Typeof variable Constructor
{An: "object "} Object Object
["An", "array"] Object Array
Function (){} Function Function
"A string" String String
55 Number Number
True Boolean Boolean
New User () Object User
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: 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.