Web Front End Learning-first lesson JavaScript

Source: Internet
Author: User

Q1: What are the data types?

5 Simple data types: undefined,null,boolean,number,string;

1 Complex data types: object.

Undefined only one value: undefined;

Null has only one value: null; (Represents an empty object pointer)

Boolean has two literal values: true,false; (case-sensitive, true and false, etc. are not Boolean, just identifiers)

Number value: Integer, floating point, decimal, octal (first bit must be 0, strict mode is not valid), Hex (first two digits must be 0x), numeric range (most browsers number.min_value:5e-324; number.max_value:1.7976931348623157e+308, you can use Isfinite (number) to determine whether the range, the super-range after the positive number automatically converted to Infinity value, negative for-infinity); NaN (not a number); Numeric conversions: Numbers ("123") ... ; parseint ("123blue"); parseint ("AF", 16), the second parameter is the number of transitions used in the conversion, parsefloat ("0xA"); Parsefloat ("3.125e7");

String type: Character literal (\b,\f,\\), string can be added, converted to string, age.tostring ();

Alert (String (value));

Object type: combination of data and function; var o = new Object (); Properties and methods: Constructor;hasownproperty (PropertyName); ispropertypeof (Object); Propertyisenumberable (Propername) (checks if the property can use the for-in statement); tolocalstring;tosting (); ValueOf ().

Q2: What are function definitions and object definitions?

function definition: 1. function declaration

function Fun () {

Expression ....

};

function expression

Var fun = function () {

Expression ....

}

Var fun1 = function fun2 () {

Expression .....

}//FUN1 () =fun2 ()

Var MyObject = new Object ();

Myobject.fun = function () {

Expression .....

}

function expression

Var fun = new function () {

Expression .....

}

Var Creatfun (parameter) {

Return fun1 (parameter1,parameter2,..., expression ...);

}//use: creatfun.fun1 (Parameter1,parameter2 ...)

Object definition: (http://www.w3school.com.cn/js/pro_js_object_defining.asp)

Original mode: var obj = new Object;

Obj.att= ""; obj.fun = function () {};

Factory mode:

Function Creatobj () {

Var obj1 = new Object;

Obj1.att = ""; Obj1.fun = function () {};

Return obj1;

}

Constructor method:

Function Creatobj () {

This.att = "";

THIS.ATT1 = "";

Obj1.fun = function () {};

}

Var OBJ = new Creatobj ();

Prototype mode:

Function obj{

}

Obj.att = "";

obj.fun1= function () {};

Var myobj1 = new OBJ ();

Constructor/prototype for

Mix:

Function car (scolor,idoors,impg)  {

  this.color = scolor;

  this.doors = idoors;

  this.mpg = impg;

  this.drivers = new array ("Mike", "John");

}

 

Car.prototype.showcolor = function ()  {

  alert ( This.color);

}

Var ocar1 = new car ("Red", 4,23);

Var ocar2 = new car ("Blue", 3,25);

OCar1.drivers.push ("Bill");

Alert (ocar1.drivers);//output   "Mike,john,bill"

Alert (ocar2.drivers);//output   "Mike,john"

Dynamic Prototyping methods:

function Car (scolor,idoors,impg) {

This.color = Scolor;

This.doors = idoors;

This.mpg = Impg;

This.drivers = new Array ("Mike", "John");

if (typeof car._initialized = = "undefined") {

Car.prototype.showColor = function () {

alert (This.color);

};

Car._initialized = true;

}

}

Var va = new Car (+/-);

Va.showcolor ();

Web Front End Learning-first lesson JavaScript

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.