Design JS script with OOP method
basic concepts:
JScript is an interpreted, object-based scripting language. You cannot use the language to write a separate running application, you can only run on an interpreter or "host", such as Active Server Pages (ASP), Internet browser or Windows script host.
JScript is a loose type language, and JScript will automatically convert as needed.
JScript supports four types of objects: built-in objects, generated objects, objects given by hosts (such as Window and Document in the Internet browser) and ActiveX objects (external components).
Built-in objects: ActiveXObject, Array, Boolean, Date, Function, Global, Math, Number, Object, RegExp, and String objects; there Error, arguments, Enumerator, regular expression object, VBArray, Dictionary, FileSystemObject, TextSream object argument, Since the latter requires that the JS version is relatively high, it is not commonly used, so this is not explained.
a) * ActiveXObject: Enable and return the reference to the Automation object.
þ Property: None;
þ Method: None;
þ Example: var outxml = new activXObject ("Microsoft.xmLDom");
b) Array: Provides support for arrays that create any data type.
þ Property: Constructor, Length, Prototype;
þ Method: Concat, Join, Reverse, SLICE, SORT, TOLOCALESTRING, TOSTRING, VALUEOF
þ Example:
Var my_Array = new arrival ();
For (i = 0; i <10; i ) {
MY_ARRAY [I] = i;
}
X = my_Array [4];
c) * Boolean: Create a new Boolean value.
þ Property: Constructor, Prototype;
þ Method: Tostring, Valueof;
þ Example:
d) Date: Enable basic memory and obtain date and time.
þ Property: Constructor, Prototype;
þ methods: getDate, getDay, getFullYear, getHours, getMilliseconds, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getUTCDate, getUTCDay, getUTCFullYear, getUTCHours, getUTCMilliSeconds, getUTCMinutes, getUTCMonth, getUTCSeconds, getVarDate, getYear, setDate, setFullYear, setHours, setMilliSeconds , setMinutes, setMonth, setSeconds, setTime, setUTCDate, setUTCFullYear, setUTCHours, setUTCMilliseconds, setUTCMinutes, setUTCMonth, setUTCSeconds, setYear, toGMTString, toLocaleString, toUTCString, toString, valueOf; static method (parse, UTC); þ example:
e) * Function: Create a new function.
þ Properties: Arguments, Caller, Constructor, Prototype
þ Method: Tostring, Valueof;
þ Example:
f) Global: is an internal object that is to focus all global methods in an object. Global objects do not have syntax. Call directly.
þ Property: infinity, nan;
þ Method: Escape, Eval, ISFINITE, ISNAN, PARSEFLOAT, PARSEINT, UNESCAPE
þ Example:
g) * Math: is an internal object that provides basic mathematical functions and constants.
þ Attribute: E, LN2, LN10, Log2e, Log10e, Pi, SQRT1_2, SQRT2;
þ Method: Static method (ABS, ACOS, ASIN, ATAN, ATAN2, CEIL, COS, Exp, Floor, Log, Max, Min, Pow, Random, Round, SiN, SQRT, TAN);
þ Example: h) Number: Objects representing numeric data types and providing numerical constants.
þ Properties: Max_Value, Min_Value, Nan, Negative_Infinity, Positive_Infinity, Constructor, Prototype
þ Method: Tostring, Valueof, Tolocalestring;
þ Example:
i) Object: Provide all JScript objects that are common.
þ Property: Constructor, Prototype;
þ Method: Tostring, Valueof, Tolocalestring;
þ Example:
j) regexp: Save the inherent global object of the regular expression pattern matching information.
þ Properties: $ 1 ... $ 9, INDEX, INPUT, LastIndex;
þ Method: None;
þ Example:
K) * String: Can be used to handle or format text strings and determine and locate sub-strings in a string.
þ Property: Constructor, Prototype, Length
þ method: anchor, big, blink, bold, charAt, charCodeAt, concat, fixed, fontcolor, fontsize, fromCharCode, indexOf, italics, lastIndexOf, link, match, replace, search, slice, small, split, strike, sub, substr , Substring, SUP, TOLOWERCASE, TOUPPERCASE, TOSTRING, VALUEOF ;;
þ Example:
Note: * is a built-in object that is commonly used in the page.
Create your own object:
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -----------------------
Function Circle (XPoint, Ypoint, Radius) {
This.x = xpoint; // The X coordinate of the center.
THIS.Y = YPOINT; / / The Y coordinate of the center.
THIS.R = radius; // The radius of the circle.
THIS.PI = Math.pi;
Circle.Prototype.Area = function () {
Return this.pi * this.r * this.r;
}
}
Function window_onload () {
VAR Acircle = New Circle (12, 12, 2);
Alert (acircle.area ());
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -----------------------
Object.prototype.x = 0;
Object.prototype.y = 0;
Object.prototype.r = 1;
Object.Prototype.pi = math.pi;
Object.prototype.Area = function () {
Return this.pi * this.r * this.r;
}
Object.prototype.create = function (XPoint, Ypoint, Radius) {
This.x = xpoint; // The X coordinate of the center.
THIS.Y = YPOINT; / / The Y coordinate of the center.
THIS.R = radius; // The radius of the circle.
}
Function window_onload () {
VAR acircle = new object ();
Acircle.create (12, 12, 2);
Alert (acircle.area ());
}