Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7538409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:06:51+00:00 2026-05-30T07:06:51+00:00

Hello I found some difficulties when implementing javascript Object.defineProperties: var book1 = {}; Object.defineProperties(book1,

  • 0

Hello I found some difficulties when implementing javascript Object.defineProperties:

var book1 = {};
Object.defineProperties(book1, {
_year: {
    value: 2004
},
edition: {
    value: 1
},
year: {
    get : function() {
        return this._year;
    },
    set : function(newValue) {
        if ((newValue - this._year) > 0) {
            this.edition += 1;
        } else if ((newValue - this._year) < 0) {
            this.edition -= 1;
        }
        this._year = newValue;
    }
}
});
book1.year = 2005;
document.write(book1.edition);  //get 1, expect 2
document.write('<br/>');
book1.year = 2006;
document.write(book1.edition); //get 1, expect 3
document.write('<br/>');

Browser: Chrome 17.0.963.56

Any answer is welcome.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:06:53+00:00Added an answer on May 30, 2026 at 7:06 am

    You have to specify writable: true as a property descriptor of _year. By default, it’s not writable, and assigning a value to a non-writable property doesn’t have any effect.

    I strongly recommend to activate the strict mode, because you will receive an error message when the assignment of a value to a read-only property fails.

    "use strict"; // <---
    Object.defineProperties(book1, {
        _year: {
            value: 2004
            writable: true  /* <-- writable set to true*/
        },
        edition: {
            value: 1,
            writable: true
        },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello I have Visual Studio 2008 Express edition, I found some add-ins like metalscroll
Hello I am using Turbo C... I just have some query, I found a
I've some javascript code: wzq.CategoryTree = function(config) { }; wzq.CategoryTree.prototype.hello = function() { alert(Hello);
Hello I want to post some data from silverlight to a website. I found
println args println args.size() println args.each{arg-> println arg} println args.class if (args.contains(Hello)) println Found
Hello this is may first question and I have found so far the following
Hello can anybody solve this please I'm creating the object in the action class
I have found some threads that explain why C++ separates .cpp and .h files
Hello as always there are some differences with looks of websites in firefox and
Hello people from stackoverflow I have found more IE7 problems (tested in compatibility mode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.