Learn Yui.ext the third day _yui. Ext Related

Source: Internet
Author: User
For a lot of confusion before the knowledge, it is necessary to comb it again: from the most basic variables start talking.

1.. Variable variable

A. Global Variable and local variables Private Variable

There is a difference between adding Var and not adding Var.
--If you do not use the keyword VAR, declare a variable, then this is a global variable, any child functions can be accessed, even if it is outside the curly braces, can be accessed;
--If you use the keyword var, the entire function can access the variable from the "curly brace {}" where it is located, such as:


function foo () {
I=8//global Variable
Alert (i)
}

function Foo2 () {
var i=88//Variable i is accessible under curly braces
alert (i);
Child ()
function Child () {alert (i)}
}
Foo (); Foo2 ()
alert (i)//I or 8 here

It is noteworthy that the function is a compile-time object that must be executed or instantiated in order to allocate the variable in memory.
The global variable habit begins with _; p.s all variables are best used with caution, and you know exactly when this variable changes!
-------"See JS Manual:
"Although it is not safe, it is a valid JScript syntax to ignore the VAR keyword in a declaration statement." At this point, the JScript interpreter gives the variable the visibility of the global scope. When declaring a variable at the procedure level, it cannot be used in a global scope, in which case the variable declaration must be in the var keyword. ”


B. Data types of variables the types of variable

Jscript has three primary data types, two types of composite data, and two special data types.

The primary (basic) data types are:

String
Numerical
Boolean
The composite (reference) data type is:

Object
Array
Special data types are:

Null
Undefined
Here's a brief description of the various object types in javascript:
Native the Object:javascript language provides objects that are not dependent on the execution host, some of which are built-in objects such as Global, Math, and some are created in the context of a script run, such as Array, Boolean, Date, Function, number, Object, REGEXP, Error.
Build-in Object:javascript language provides built-in objects that are not dependent on the execution host, such as Global, Math, and built-in objects are native object.
The host Object:javascript language provides any object that relies on the hosting environment, and all objects that are not native object are host objects, such as the WScript instance in Window,wscript in IE, any user-created class.



How do I check the object type? ******
1.typeof ()
The typeof operator returns the type information as a string. There are six possible typeof return values: "Number," "String," "Boolean," "Object," "function," and "undefined."

2. Val instanceof Array
Returns a Boolean value that indicates whether an object is an instance of a particular class.
For example, when checking an array or date type (in fact, any type is allowed, see example), you must use instance of + class name (without quotes), for example:

function foo () {}
var f = new Foo ();
Alert (f instanceof Foo2)//false

3.constructor
The use of constructor is similar to that of instance, except that a Boolean value is not returned

x = new String ("Hi");
if (X.constructor = = String)
To process (the condition is true).

What type of Var i={}? ****
Answer: Object type is equivalent to var i = new Object

object is the carrier of all objects, a little think of the parent class bar

Object objects are simple,
It only has two property and two method
These two property are:
Prototype
Constructor
These two function are:
ToString ()
ValueOf ()

so var obj = new MyObject () How to text it? In fact, it is also very simple, the text of obj is defined as follows:



var obj =
{
Properties1:1, Properties2: ' 2 ', Properties3: [3],
Method1:function () {return this. Properties1 + this. Properties3[0];},
Method2:function () {return this. Preperties2; }
};



The syntax for the literal definition of a class instance is to represent the class with a pair of "{}", which means that "{}" is completely equivalent to "new Object ()". Then "{}" within the "Key:value" organizational properties and methods, the key can be any [a-za-z0-9_] character combination, or even the beginning of the number is legitimate @_@,value is any legitimate text JavaScript data, and finally each key value pairs with "," To separate the line.
Typically used for JSON exchange data.


The two meanings of undefined
1.undefined Keyword 2.undefined properties
Declaring a variable, but not assigning a value, is the case of the first kind;
Without a declaration, a variable participates in the operation, and its data type is the second case;
The two identical names have different meanings and suggest the next version to be renamed.


var declared; Declare a variable.
if (declared = = undefined)///change to uninitialized not initialized will be more accurate, JS is loose language indeed!
document.write ("declared has not been given a value.");

if (typeOf (notdeclared) = = "undefined")
document.write ("notdeclared has not been defined.");

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.