Home > javascript > บทสรุป Object มาตรฐานใน javascript

บทสรุป Object มาตรฐานใน javascript

March 16th, 2009

ออปเจ็คต์มาตรฐานในจาวาสคริปต์ (จาก w3schools.com)

ในบทความนี้ก็จะเป็นส่วนสุดท้ายสำหรับ javascript เบื้องต้น แล้วนะครับ เป็นการรวม method และ function มาตรฐาน ที่ javascript ได้เตรียมไว้ให้เรียกใช้งานได้ซึ่งได้นำมาจากเว็บ w3school.com นะครับ หลังจากบทความนี้จบ ก็จะเป็นตัวอย่าง ในการใช้งานสำคัญของ javascript อื่นๆนะครับ

Array Object Methods

FF: Firefox, N: Netscape, IE: Internet Explorer

Method

Description

FF

N

IE

concat()

Joins two or more arrays and returns the result

1

4

4

join()

Puts all the elements of an array into a string. The elements are separated by a specified delimiter

1

3

4

pop()

Removes and returns the last element of an array

1

4

5.5

push()

Adds one or more elements to the end of an array and returns the new length

1

4

5.5

reverse()

Reverses the order of the elements in an array

1

3

4

shift()

Removes and returns the first element of an array

1

4

5.5

slice()

Returns selected elements from an existing array

1

4

4

sort()

Sorts the elements of an array

1

3

4

splice()

Removes and adds new elements to an array

1

4

5.5

toSource()

Represents the source code of an object

1

4

-

toString()

Converts an array to a string and returns the result

1

3

4

unshift()

Adds one or more elements to the beginning of an array and returns the new length

1

4

6

valueOf()

Returns the primitive value of an Array object

1

2

4

 


Array Object Properties

Property

Description

FF

N

IE 

constructor

A reference to the function that created the object

1

2

4

index

 

1

3

4

input

 

1

3

4

length

Sets or returns the number of elements in an array

1

2

4

prototype

Allows you to add properties and methods to the object

1

2

4

 


 

Boolean Object Methods

FF: Firefox, N: Netscape, IE: Internet Explorer

Method

Description

FF

N

IE

toSource()

Represents the source code of an object

1

4

-

toString()

Converts a Boolean value to a string and returns the result

1

4

4

valueOf()

Returns the primitive value of a Boolean object

1

4

4

 


Boolean Object Properties

Property

Description

FF

N

IE 

constructor

A reference to the function that created the object

1

2

4

prototype

Allows you to add properties and methods to the object

1

2

4

 


Date Object Methods

FF: Firefox, N: Netscape, IE: Internet Explorer

Method

Description

FF

N

IE

Date()

Returns today’s date and time

1

2

3

getDate()

Returns the day of the month from a Date object (from 1-31)

1

2

3

getDay()

Returns the day of the week from a Date object (from 0-6)

1

2

3

getMonth()

Returns the month from a Date object (from 0-11)

1

2

3

getFullYear()

Returns the year, as a four-digit number, from a Date object

1

4

4

getYear()

Returns the year, as a two-digit or a four-digit number, from a Date object. Use getFullYear() instead !!

1

2

3

getHours()

Returns the hour of a Date object (from 0-23)

1

2

3

getMinutes()

Returns the minutes of a Date object (from 0-59)

1

2

3

getSeconds()

Returns the seconds of a Date object (from 0-59)

1

2

3

getMilliseconds()

Returns the milliseconds of a Date object (from 0-999)

1

4

4

getTime()

Returns the number of milliseconds since midnight Jan 1, 1970

1

2

3

getTimezoneOffset()

Returns the difference in minutes between local time and Greenwich Mean Time (GMT)

1

2

3

getUTCDate()

Returns the day of the month from a Date object according to universal time (from 1-31)

1

4

4

getUTCDay()

Returns the day of the week from a Date object according to universal time (from 0-6)

1

4

4

getUTCMonth()

Returns the month from a Date object according to universal time (from 0-11)

1

4

4

getUTCFullYear()

Returns the four-digit year from a Date object according to universal time

1

4

4

getUTCHours()

Returns the hour of a Date object according to universal time (from 0-23)

1

4

4

getUTCMinutes()

Returns the minutes of a Date object according to universal time (from 0-59)

1

4

4

getUTCSeconds()

Returns the seconds of a Date object according to universal time (from 0-59)

1

4

4

getUTCMilliseconds()

Returns the milliseconds of a Date object according to universal time (from 0-999)

1

4

4

parse()

Takes a date string and returns the number of milliseconds since midnight of January 1, 1970

1

2

3

setDate()

Sets the day of the month in a Date object (from 1-31)

1

2

3

setMonth()

Sets the month in a Date object (from 0-11)

1

2

3

setFullYear()

Sets the year in a Date object (four digits)

1

4

4

setYear()

Sets the year in the Date object (two or four digits). Use setFullYear() instead !!

1

2

3

setHours()

Sets the hour in a Date object (from 0-23)

1

2

3

setMinutes()

Set the minutes in a Date object (from 0-59)

1

2

3

setSeconds()

Sets the seconds in a Date object (from 0-59)

1

2

3

setMilliseconds()

Sets the milliseconds in a Date object (from 0-999)

1

4

4

setTime()

Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970

1

2

3

setUTCDate()

Sets the day of the month in a Date object according to universal time (from 1-31)

1

4

4

setUTCMonth()

Sets the month in a Date object according to universal time (from 0-11)

1

4

4

setUTCFullYear()

Sets the year in a Date object according to universal time (four digits)

1

4

4

setUTCHours()

Sets the hour in a Date object according to universal time (from 0-23)

1

4

4

setUTCMinutes()

Set the minutes in a Date object according to universal time (from 0-59)

1

4

4

setUTCSeconds()

Set the seconds in a Date object according to universal time (from 0-59)

1

4

4

setUTCMilliseconds()

Sets the milliseconds in a Date object according to universal time (from 0-999)

1

4

4

toSource()

Represents the source code of an object

1

4

-

toString()

Converts a Date object to a string

1

2

4

toGMTString()

Converts a Date object, according to Greenwich time, to a string. Use toUTCString() instead !!

1

2

3

toUTCString()

Converts a Date object, according to universal time, to a string

1

4

4

toLocaleString()

Converts a Date object, according to local time, to a string

1

2

3

UTC()

Takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time

1

2

3

valueOf()

Returns the primitive value of a Date object

1

2

4

 


Date Object Properties

Property

Description

FF

N

IE 

constructor

A reference to the function that created the object

1

4

4

prototype

Allows you to add properties and methods to the object

1

3

4

 


Math Object Methods

FF: Firefox, N: Netscape, IE: Internet Explorer

Method

Description

FF

N

IE

abs(x)

Returns the absolute value of a number

1

2

3

acos(x)

Returns the arccosine of a number

1

2

3

asin(x)

Returns the arcsine of a number

1

2

3

atan(x)

Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians

1

2

3

atan2(y,x)

Returns the angle theta of an (x,y) point as a numeric value between -PI and PI radians

1

2

3

ceil(x)

Returns the value of a number rounded upwards to the nearest integer

1

2

3

cos(x)

Returns the cosine of a number

1

2

3

exp(x)

Returns the value of Ex

1

2

3

floor(x)

Returns the value of a number rounded downwards to the nearest integer

1

2

3

log(x)

Returns the natural logarithm (base E) of a number

1

2

3

max(x,y)

Returns the number with the highest value of x and y

1

2

3

min(x,y)

Returns the number with the lowest value of x and y

1

2

3

pow(x,y)

Returns the value of x to the power of y

1

2

3

random()

Returns a random number between 0 and 1

1

2

3

round(x)

Rounds a number to the nearest integer

1

2

3

sin(x)

Returns the sine of a number

1

2

3

sqrt(x)

Returns the square root of a number

1

2

3

tan(x)

Returns the tangent of an angle

1

2

3

toSource()

Represents the source code of an object

1

4

-

valueOf()

Returns the primitive value of a Math object

1

2

4

 


Math Object Properties

Property

Description

FF

N

IE 

constructor

A reference to the function that created the object

1

2

4

E

Returns Euler’s constant (approx. 2.718)

1

2

3

LN2

Returns the natural logarithm of 2 (approx. 0.693)

1

2

3

LN10

Returns the natural logarithm of 10 (approx. 2.302)

1

2

3

LOG2E

Returns the base-2 logarithm of E (approx. 1.442)

1

2

3

LOG10E

Returns the base-10 logarithm of E (approx. 0.434)

1

2

3

PI

Returns PI (approx. 3.14159)

1

2

3

prototype

Allows you to add properties and methods to the object

1

2

4

SQRT1_2

Returns the square root of 1/2 (approx. 0.707)

1

2

3

SQRT2

Returns the square root of 2 (approx. 1.414)

1

2

3

 


String Object Methods

FF: Firefox, N: Netscape, IE: Internet Explorer

Method

Description

FF

N

IE

anchor()

Creates an HTML anchor

1

2

3

big()

Displays a string in a big font

1

2

3

blink()

Displays a blinking string

1

2

 

bold()

Displays a string in bold

1

2

3

charAt()

Returns the character at a specified position

1

2

3

charCodeAt()

Returns the Unicode of the character at a specified position

1

4

4

concat()

Joins two or more strings

1

4

4

fixed()

Displays a string as teletype text

1

2

3

fontcolor()

Displays a string in a specified color

1

2

3

fontsize()

Displays a string in a specified size

1

2

3

fromCharCode()

Takes the specified Unicode values and returns a string

1

4

4

indexOf()

Returns the position of the first occurrence of a specified string value in a string

1

2

3

italics()

Displays a string in italic

1

2

3

lastIndexOf()

Returns the position of the last occurrence of a specified string value, searching backwards from the specified position in a string

1

2

3

link()

Displays a string as a hyperlink

1

2

3

match()

Searches for a specified value in a string

1

4

4

replace()

Replaces some characters with some other characters in a string

1

4

4

search()

Searches a string for a specified value

1

4

4

slice()

Extracts a part of a string and returns the extracted part in a new string

1

4

4

small()

Displays a string in a small font

1

2

3

split()

Splits a string into an array of strings

1

4

4

strike()

Displays a string with a strikethrough

1

2

3

sub()

Displays a string as subscript

1

2

3

substr()

Extracts a specified number of characters in a string, from a start index

1

4

4

substring()

Extracts the characters in a string between two specified indices

1

2

3

sup()

Displays a string as superscript

1

2

3

toLowerCase()

Displays a string in lowercase letters

1

2

3

toUpperCase()

Displays a string in uppercase letters

1

2

3

toSource()

Represents the source code of an object

1

4

-

valueOf()

Returns the primitive value of a String object

1

2

4

 


String Object Properties

Property

Description

FF

N

IE

constructor

A reference to the function that created the object

1

4

4

length

Returns the number of characters in a string

1

2

3

prototype

Allows you to add properties and methods to the object

1

2

4

 


Top-level Functions

FF: Firefox, N: Netscape, IE: Internet Explorer

Function

Description

FF

N

IE

decodeURI()

Decodes an encoded URI

1

4

5.5

decodeURIComponent()

Decodes an encoded URI component

1

4

5.5

encodeURI()

Encodes a string as a URI

1

4

5.5

encodeURIComponent()

Encodes a string as a URI component

1

4

5.5

escape()

Encodes a string

1

-

3

eval()

Evaluates a string and executes it as if it was script code

1

2

3

isFinite()

Checks if a value is a finite number

1

4

4

isNaN()

Checks if a value is not a number

1

2

3

Number()

Converts an object’s value to a number

1

 

 

parseFloat()

Parses a string and returns a floating point number

1

2

3

parseInt()

Parses a string and returns an integer

1

2

3

String()

Converts an object’s value to a string

1

 

 

unescape()

Decodes a string encoded by escape()

1

-

3

 


Top-level Properties

Property

Description

FF

N

IE 

Infinity

A numeric value that represents positive or negative infinity

1

4

4

NaN

Indicates that a value is “Not a Number”

1

4

4

undefined

Indicates that a variable has not been assigned a value

1

4

5.5

 

 

หมายเหตุ เอกสารนี้สรุปและมีข้อมูลต่างๆ จากเว็บไซต์ต่อไปนี้

http://www.w3schools.com/js_ref/default.asp

http://www.w3schools.com/js/default.asp

http://www.javascriptkit.com/jsref/

admin javascript

  1. No comments yet.
  1. No trackbacks yet.