Code _javascript tips for getting unknown object properties in JavaScript

Source: Internet
Author: User
These two days to try to write a ajaxtoolkit:asyncfileupload demo, it has a Onclientuploadcomplete attribute can associate client JS, so you can write onclientuploadcomplete= " Uploadcomplete, and then define the Uploadcomplete method:
Copy Code code as follows:

function Uploadcomplete (sender, E) {
Do something ...
}

But how do you get information about uploading files from E? In addition to looking at the source code of AjaxControlToolkit, you can also use JS:
Copy Code code as follows:

function Uploadcomplete (sender, E) {
var ret = "properties:\n";
For (Var prop in E) {
var val = E[prop];
if (typeof (val) = = "function") {
RET + + (prop + "()");
}
else {
RET + + prop + ":" + val;
}
ret = "; \ n";
}
alert (ret);
}

Results:

So it's clear.

Here is the use of JS "associative array" concept, JS object properties (including methods, can also be considered to be attributes) is stored in its associative array, through the for...in ... You can iterate over it.

With regard to associative arrays, we can use this:

Copy Code code as follows:

var dog = new Object ();
Dog.id = 1;
dog["name"] = "Gougou";
Alert ("ID:" + dog["id"] + ", name" + dog.name);

Get: "Id:1, Name:gougou"

This article is original, reproduced please specify: from Freeway--cnblogs

Related Article

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.