JS Object.defineproperty Use

Source: Internet
Author: User


Object.defineproperty (obj, prop, descriptor)

Parameter description:

OBJ: Required. Target Object
Prop: Required. The name of the property that needs to be defined or modified
Descriptor: Required. Attributes owned by the target property

return value:

The object passed into the function. That is, the first parameter, obj.

For attributes, we can set some properties for this property, such as whether it is read-only or not, and whether it can be used for . in or Object.keys () traversal.


<!DOCTYPE HTML><HTMLLang= "zh">    <Head>        <MetaCharSet= "UTF-8" />        <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0" />        <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge" />        <title>Object.defineproperty Example</title>    </Head>    <Body>        <ul>            <LiID= "First">1</Li>            <Li>2</Li>            <Li>3</Li>        </ul>        <Scripttype= "Text/javascript">            varSS={age:Ten            }; varname= 'Mfg'; Object.defineproperty (SS,'name', {                //sets whether it is possible to enumerateEnumerable:false,                //Whether you can delete the target property or modify the property againConfigurable:false,                //Get Property valueget () {returnname; },                //Setting property valuesSet (val) {name=Val; }}) Console.log (ss.name) ss.name= 'New Value';        Console.log (Ss.name); </Script>    </Body></HTML>

Ref: 1190000007434923

JS Object.defineproperty Use

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.