Code for retrieving unknown object attributes in JavaScript

Source: Internet
Author: User

In the past two days, I tried to write a Demo of AjaxToolkit: AsyncFileUpload. It has an OnClientUploadComplete attribute that can be associated with client JS, so I can write OnClientUploadComplete = "uploadComplete" and then define the uploadcomple: Copy codeThe Code is as follows: function uploadComplete (sender, e ){
// Do something here...
}

But how can I obtain the information of the uploaded file from e? In addition to viewing the source code of AjaxControlToolkit, you can also use JS:Copy codeThe Code is 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 );
}

Result:

In this way, you will understand.

The concept of "associated array" in JS is used here. Attributes of JS objects (including methods, or attributes) are stored in their associated arrays, through... in... you can traverse.

We can use the following link array:

Copy codeThe Code is 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. For more information, see: 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.