Студопедия.Орг Главная | Случайная страница | Контакты | Мы поможем в написании вашей работы!  
 

Клиентские сценарии. Язык JavaScript. Объекты Function, Object, Number



https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Functions

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number

Каждая функция в JavaScript это фактически объект Function.

new Function ([ arg1 [, arg2 [,... argN ]],] functionBody)

In JavaScript, functions are first-class objects, i.e. they are objects and can be manipulated and passed around like just like any other object.

var multiply = new Function("x", "y", "return x * y");var theAnswer = multiply(7, 6); function myFunc(theObject) { theObject.brand = "Toyota"; } var mycar = {brand: "Honda", model: "Accord", year: 1998}; alert(mycar.brand); // shows 'Honda' myFunc(mycar); // pass object mycar to the function alert(mycar.brand); // shows 'Toyota' as the brand property of // mycar was changed by the function)

new Object([ value ])

The Object constructor creates an object wrapper for the given value. If the value is null or undefined, it will create and return an empty object, otherwise, it will return an object of type that corresponds to the given value.

o = new Object(true); // equivalent to o = new Boolean(true);o = new Object(Boolean()); // equivalent to o = new Boolean(false);

constructor property:

o = new Object // or o = {} in JavaScript 1.2o.constructor == Object

All objects in JavaScript are descended from Object; all objects inherit methods and properties from Object.prototype, although they may be overridden. For example, other constructors' prototypes override the constructor property and provide their own toString methods. Changes to the Object prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.

new Number(value)

The primary uses for the Number object are:

If the argument cannot be converted into a number, it returns NaN.

In a non-constructor context (i.e., without the new operator), Number can be used to perform a type conversion.

biggestNum = Number.MAX_VALUE;smallestNum = Number.MIN_VALUE;infiniteNum = Number.POSITIVE_INFINITY;negInfiniteNum = Number.NEGATIVE_INFINITY;notANum = Number.NaN;




Дата публикования: 2015-01-13; Прочитано: 257 | Нарушение авторского права страницы | Мы поможем в написании вашей работы!



studopedia.org - Студопедия.Орг - 2014-2024 год. Студопедия не является автором материалов, которые размещены. Но предоставляет возможность бесплатного использования (0.005 с)...