JS04---Object1

Source: Internet
Author: User
Tags hasownproperty

So far most of the reference types are instances of type object, and object is also the most used type in ECMAScript (just like Java.lang.Object, the object type is the basis of all its instances). How the object type is created, using the for-in enumeration for the object type loop object Each instance will have the following properties and methods: Constructor: Holds the function that is used to create the current object. (constructor) hasOwnProperty (PropertyName): Used to detect whether a given property exists in the current object instance, not in the prototype. isPrototypeOf (object): Used to check if an incoming object is a prototype of another object. propertyIsEnumerable (PropertyName): Used to check whether a given property can be enumerated using the For-in statement. toLocaleString (): Returns the string representation of the object. The string corresponds to the region of the execution environment. ToString (): Returns the string representation of the object. ValueOf (): Returns the string, numeric, or Boolean representation of an object.
<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD"><HTML>    <Head>        <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />        <title>Untitled Document</title>        <Scripttype=text/javascriptCharSet=utf-8>/*var obj = {}; Obj.say = function FF () {//The outside of FF here is an alert (' Hello world! ') that cannot be used; }ff ();//FF is not defined, equivalent to window. FF (), no window. FF = function () {}var f = new FF ();//ff is not defined*/        //Object base class for all classes        varobj1= NewObject (); varobj= {} ; //instantiate the object, as in 2,        //setting properties for an objectObj.name= 'Zhang 3'; Obj.age=  - ; Obj.sex= 'male'; obj["Birthday"] = '1980-08-07'; Obj.say= function(){  //Anonymous ObjectsAlert ('Hello world!'); }        //accessing an object's properties or methodsalert (obj.name);        alert (obj.age);                Obj.say (); //The delete operator deletes the properties or methods of the object.        DeleteObj.age; DeleteObj.say;        alert (obj.name); alert (obj.age);//undefinedalert (obj.sex); Obj.say ();//say is not a fuchtion                //iterate over the JS object to facilitate JSON,         for(varattributeinchobj) {Alert (attribute+ typeofattribute+" : "+Obj[attribute]); //Obj[attribute] To use the brackets, do not use the dot.         }        //name string: 3, age string:20, sex string: Male, birthday string:1980-08-07, say String:function () {alert (' Hel Lo world! ');}                        //constructor create function for saving objectsalert (obj.constructor);//function Onject () {}        vararr= [] ; alert (arr.constructor);//function Array () {}                //hasOwnProperty (PropertyName) is used to detect whether a given property exists in an objectalert (Obj.hasownproperty ('Sex')); //isprototypeof (Object) detection prototype                //detects whether a given property can be enumerated by the inalert (obj.propertyisenumerable ('say')); </Script>    </Head>    <Body>    </Body></HTML>

Js04---object1

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.