Microsoft JScript runtime error object does not support this attribute or Method

Source: Internet
Author: User

"Do not name JS function names and page element names with the same name. Otherwise, an unexpected error occurs. 』

Microsoft JScript objects are a collection of properties and methods.
A method is a function that is a member of an object.
An attribute is a value or a group of values (in the form of an array or object) and a member of an object.
JScript supports four types of objects:
Internal objects, generated objects, objects provided by the host (such as windows and document in the Internet browser), and ActiveX objects (external components ).
In JScript, objects and arrays are processed in almost the same way.
Objects and arrays can be assigned any value. In fact, arrays are only special objects.
The difference between an array and an object is that an array has a "Fantastic" Length attribute, but the object does not.
This means that an element of the array can be given a value greater than other elements.
For example, myarray [100] = "hello", then the Length attribute is automatically updated to 101 (New length ).
Similarly, if you modify the Length attribute of an array, the elements that are no longer part of the array will be deleted.
All objects in JScript support the "expando" attribute or those attributes that can be dynamically added or deleted at runtime.
These attributes can contain any number name.
If the property name is a simple identifier <reference identifier rules>, you can add a period after the object name,
For example, VAR myobj = new object ();
// Add two expando attributes, 'name' and 'age'
Myobj. Name = "Fred ";
Myobj. Age = 42;
If the property name is not a simple identifier or is unknown when writing a script, you can use any expression in square brackets to index the property.
In JScript, the names of all expando attributes are converted to strings before being added to an object.
VaR myobj = new object ();
// Add two expando attributes that cannot be written in the object. Property syntax.
// The first attribute contains invalid characters (spaces), so it must be written in square brackets.
Myobj ["not avalid identifier"] = "this is the property value ";
// The second expando name is a number, so it must also be written in square brackets.
Myobj [100] = "100 ";
The traditional method is to assign the array element a numerical index starting with 0. These array elements interact with the Length attribute.
However, because all arrays are objects, the expando attribute is also supported.
However, the expando attribute does not interact with the Length attribute in any way.
For example:
// Array of three elements
VaR myarray = new array (3 );
// Add data
Myarray [0] = "hello ";
Myarray [1] = 42;
Myarray [2] = new date (2000,1, 1 );
// Display the length of the array 3
Window. Alert (myarray. Length );
// Add some expando attributes
Myarray. expando = "jscript! ";
Myarray ["another expando"] = "Windows ";
// 3 is displayed, because the two expando attributes do not affect the length.
Window. Alert (myarray. Length );
Although JScript does not directly support multi-dimensional arrays, it can store any type of data (including other arrays) in array elements ).
Therefore, you can obtain the multi-dimensional array feature by storing other arrays in the element of another array.
For example, the following code creates a multiplication table for a number up to 5:
// Change the number of tables if they are larger.
VaR imaxnum = 5;
// Cyclic count
VaR I, J;
// New array. The array size is imaxnum + 1 because the array starts counting from 0 instead of 1.
VaR multiplicationtable = new array (imaxnum + 1 );
// Cycle each major number (each row in the table)
For (I = 1; I <= imaxnum; I ++)
{
// Generate columns in the table
Multiplicationtable [I] = new array (imaxnum + 1 );
// Store the result of multiplication in the row for (j = 1; j <= imaxnum; j ++)
{
Multiplicationtable [I] [J] = I * J;
}
}
Window. Alert (multiplicationtable [3] [4]); // display 12
Window. Alert (multiplicationtable [5] [2]); // display 10
Window. Alert (multiplicationtable [1] [4]); // display 4

"Source: www.ititgo.com 』

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.