Uvod

js this

U sklopu samog JavaScript-a postoje ugradjeni objekti sa svojim svojstvima i metodama, namenjeni da olakšaju programiranje.

  • Array
  • Math
  • Date
  • Function

Pored navedenih objekata postoje još i objekti čija imena su ista kao imena prostih primitiva (samo sa velikim početnim slovom):

  • String
  • Number

Ovi objekti sa “opremljeni” metodama potrebnim za rad sa odgovarajućim tipom podataka i zamišljeni su da olakšaju rad sa primitivnim tipovima. Kada se pojavi potreba za operacijom nad takvim primitivnim tipom, kompajler automatski “obmotava” prost tip u njegov “parnjak” objekat nakon čega su dostupne sve metode ugradjenog objekta.

U ovom članku sam želeo da pregledno okupim na jednom mestu sve metode i svojstva objekata ugradjenih u javascript-u.

“String” kao objekat

Matode koje mogu da se primene na string objekat:

Metode String objekta

Metoda objekta Opis
charAt() Returns the character at the specified index (position)
charCodeAt() Returns the Unicode of the character at the specified index
concat() Joins two or more strings, and returns a new joined strings
fromCharCode() Converts Unicode values to characters
indexOf() Returns the position of the first found occurrence of a specified value in a string
lastIndexOf() Returns the position of the last found occurrence of a specified value in a string
localeCompare() Compares two strings in the current locale
match() Searches a string for a match against a regular expression, and returns the matches
replace() Searches a string for a specified value, or a regular expression, and returns a new string
where the specified values are replaced
search() Searches a string for a specified value, or regular expression, and returns the position of the
match
slice() Extracts a part of a string and returns a new string
split() Splits a string into an array of substrings
substr() Extracts the characters from a string, beginning at a specified start position, and through the
specified number of character
substring() Extracts the characters from a string, between two specified indices
toLocaleLowerCase() Converts a string to lowercase letters, according to the host’s locale
toLocaleUpperCase() Converts a string to uppercase letters, according to the host’s locale
toLowerCase() Converts a string to lowercase letters
toString() Returns the value of a String object
toUpperCase() Converts a string to uppercase letters
trim() Removes whitespace from both ends of a string
valueOf() Returns the primitive value of a String object

Metode koje obavijaju “string” HTML tagom

Sledeće metode vraćaju string obavijen sa HTML tagom (eventualno nekim HTML atributom).

Metoda objekta Opis
anchor() Creates an anchor
big() Displays a string using a big font
blink() Displays a blinking string
bold() Displays a string in bold
fixed() Displays a string using a fixed-pitch font
fontcolor() Displays a string using a specified color
fontsize() Displays a string using a specified size
italics() Displays a string in italic
link() Displays a string as a hyperlink
small() Displays a string using a small font
strike() Displays a string with a strikethrough
sub() Displays a string as subscript text
sup() Displays a string as superscript text

“Number” kao objekat

Number je objekat koji ima ugradjene sledeće metode:

Metod Opis metoda
isFinite() Checks whether a value is a finite number
isInteger() Checks whether a value is an integer
isNaN() Checks whether a value is Number.NaN
isSafeInteger() Checks whether a value is a safe integer
toExponential(x) Converts a number into an exponential notation
toFixed(x) Formats a number with x numbers of digits after the decimal point
toPrecision(x) Formats a number to x length
toString() Converts a number to a string
valueOf() Returns the primitive value of a number

“Function” kao objekat

Function je objekat koji ima ugradjene sledeće metode:

Metod Opis metoda
Function.prototype.apply() Ova metoda daje izabranoj funkciji željeno značenje ključne reči “this”, stim što odmah poziva funkciju (eng. invoke). Kroz prvi argument definiše na koji objekat će ukazivati ključna reč this, dok su ostali argumenti koji se prosledjuju kroz array, podaci potrebni početnoj funkciji.
Function.prototype.bind() Function.prototype.bind()Ova metoda daje izabranoj funkciji željeno značenje ključne reči “this”. Kroz prvi argument definiše na koji objekat će ukazivati ključna reč this, dok su ostali argumenti koji se prosledjuju kao lista argumenata, podaci potrebni početnoj funkciji.
Function.prototype.call() Function.prototype.call()Ova metoda daje izabranoj funkciji željeno značenje ključne reči “this”, stim što odmah poziva funkciju (eng. invoke). Kroz prvi argument definiše na koji objekat će ukazivati ključna reč this, dok su ostali argumenti koji se prosledjuju kao lista argumenata, podaci potrebni početnoj funkciji.

Array objekat

Metode koje se mogu primeniti na objekat array su sledeće:

Metoda Opis
concat() Joins two or more arrays, and returns a copy of the joined arrays
copyWithin() Copies array elements within the array, to and from specified positions
every() Checks if every element in an array pass a test
fill() Fill the elements in an array with a static value
filter() Creates a new array with every element in an array that pass a test
find() Returns the value of the first element in an array that pass a test
findIndex() Returns the index of the first element in an array that pass a test
forEach() Calls a function for each array element
indexOf() Search the array for an element and returns its position
isArray() Checks whether an object is an array
join() Joins all elements of an array into a string
lastIndexOf() Search the array for an element, starting at the end, and returns its position
map() Creates a new array with the result of calling a function for each array element
pop() Removes the last element of an array, and returns that element
push() Adds new elements to the end of an array, and returns the new length
reduce() Reduce the values of an array to a single value (going left-to-right)
reduceRight() Reduce the values of an array to a single value (going right-to-left)
reverse() Reverses the order of the elements in an array
shift() Removes the first element of an array, and returns that element
slice() Selects a part of an array, and returns the new array
some() Checks if any of the elements in an array pass a test
sort() Sorts the elements of an array
splice() Adds/Removes elements from an array
toString() Converts an array to a string, and returns the result
unshift() Adds new elements to the beginning of an array, and returns the new length
valueOf() Returns the primitive value of an array

Math objekat

Svojstva Math objekta

Svojstva Math objekta vraćaju neku od poznatih matematičkih konstanti:

Svojstvo objekta Opis
E Returns Euler’s number (approx. 2.718)
LN2 Returns the natural logarithm of 2 (approx. 0.693)
LN10 Returns the natural logarithm of 10 (approx. 2.302)
LOG2E Returns the base-2 logarithm of E (approx. 1.442)
LOG10E Returns the base-10 logarithm of E (approx. 0.434)
PI Returns PI (approx. 3.14)
SQRT1_2 Returns the square root of 1/2 (approx. 0.707)
SQRT2 Returns the square root of 2 (approx. 1.414)

Math metode

Metode Math objekta uzimaju broj kao atribut a vraćaju rezultat neke matematičke operacije nad tim brojem:

Metoda objekta Opis
abs(x) Returns the absolute value of x
acos(x) Returns the arccosine of x, in radians
asin(x) Returns the arcsine of x, in radians
atan(x) Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y,x) Returns the arctangent of the quotient of its arguments
ceil(x) Returns x, rounded upwards to the nearest integer
cos(x) Returns the cosine of x (x is in radians)
exp(x) Returns the value of Ex
floor(x) Returns x, rounded downwards to the nearest integer
log(x) Returns the natural logarithm (base E) of x
max(x,y,z,…,n) Returns the number with the highest value
min(x,y,z,…,n) Returns the number with the lowest value
pow(x,y) Returns the value of x to the power of y
random() Returns a random number between 0 and 1
round(x) Rounds x to the nearest integer
sin(x) Returns the sine of x (x is in radians)
sqrt(x) Returns the square root of x
tan(x) Returns the tangent of an angle

Datum objekat

Date je objekat u javascriptu koji je zadužen za datum i vreme a metode koje mogu da se primene na taj objekat su sledeće:

Metoda objekta Opis
getDate() Returns the day of the month (from 1-31)
getDay() Returns the day of the week (from 0-6)
getFullYear() Returns the year (four digits)
getHours() Returns the hour (from 0-23)
getMilliseconds() Returns the milliseconds (from 0-999)
getMinutes() Returns the minutes (from 0-59)
getMonth() Returns the month (from 0-11)
getSeconds() Returns the seconds (from 0-59)
getTime() Returns the number of milliseconds since midnight Jan 1, 1970
getTimezoneOffset() Returns the time difference between UTC time and local time, in minutes
getUTCDate() Returns the day of the month, according to universal time (from 1-31)
getUTCDay() Returns the day of the week, according to universal time (from 0-6)
getUTCFullYear() Returns the year, according to universal time (four digits)
getUTCHours() Returns the hour, according to universal time (from 0-23)
getUTCMilliseconds() Returns the milliseconds, according to universal time (from 0-999)
getUTCMinutes() Returns the minutes, according to universal time (from 0-59)
getUTCMonth() Returns the month, according to universal time (from 0-11)
getUTCSeconds() Returns the seconds, according to universal time (from 0-59)
parse() Parses a date string and returns the number of milliseconds since January 1, 1970
setDate() Sets the day of the month of a date object
setFullYear() Sets the year (four digits) of a date object
setHours() Sets the hour of a date object
setMilliseconds() Sets the milliseconds of a date object
setMinutes() Set the minutes of a date object
setMonth() Sets the month of a date object
setSeconds() Sets the seconds of a date object
setTime() Sets a date to a specified number of milliseconds after/before January 1, 1970
setUTCDate() Sets the day of the month of a date object, according to universal time
setUTCFullYear() Sets the year of a date object, according to universal time (four digits)
setUTCHours() Sets the hour of a date object, according to universal time
setUTCMilliseconds() Sets the milliseconds of a date object, according to universal time
setUTCMinutes() Set the minutes of a date object, according to universal time
setUTCMonth() Sets the month of a date object, according to universal time
setUTCSeconds() Set the seconds of a date object, according to universal time
toDateString() Converts the date portion of a Date object into a readable string
toISOString() Returns the date as a string, using the ISO standard
toJSON() Returns the date as a string, formatted as a JSON date
toLocaleDateString() Returns the date portion of a Date object as a string, using locale conventions
toLocaleTimeString() Returns the time portion of a Date object as a string, using locale conventions
toLocaleString() Converts a Date object to a string, using locale conventions
toString() Converts a Date object to a string
toTimeString() Converts the time portion of a Date object to a string
toUTCString() Converts a Date object to a string, according to universal time
UTC() Returns the number of milliseconds in a date since midnight of January 1, 1970, according to
UTC time
valueOf() Returns the primitive value of a Date object
Podelite:

Ostavite komentar