javascript - Object property cannot be set via setter while using Object.create -


On your attempt to know more about the object. I came across.

An example page from the top:

  var car2 = object. Create (empty); // This is an empty object, such as {} Car2.prototype = {getInfo: function () {return 'a' + this.color + '' + this.desc + '.'; '; }}; Var car2 = Object.create (Car2.prototype, {// value properties color: {writeable: true, configurable: true, value: 'red'}, // concrete rick value rawDesc: {writeable: false, configurable: true, Price: 'Porsche Boxer'}, // Data Properties (Assigned using Gates and Sets) desc: {Configure: True, Receive: Function () {return.rawDesc.toUpperCase ();}, set : Function (value) {This.rawDesc = value.toLowerCase ();}}}); Car2.color = 'Blue'; Warning (car2.getInfo ()); // Display 'A Blue Porsche Boxer.'   

Question:

  1. How accurate is the above example? It seems that rawDesc can be a private member, which can only be modified through desc code>. Is it useful in any way?

  2. In addition, desc for car2.desc = 'Merc' does not seem to work so why is?

  3. Parts of the object. Are phyproporty and object.Sent?

    Research:

    Some related questions: I tried to delete the writable: incorrect and value : 'Porsche Boxer' and tried to set the value but there is no benefit.

    some comments:

      var Car2 = Object.create (zero ); // This is an empty object, such as {}   

    The comment is not perfect at all. The internal prototype of Car2 [[prototype]] will be null , so it will be object.prototype , While an object is created using {} .

      Car2.prototype = {...}; Var car2 = Object.create (Car2.prototype, {  

    It seems there is no point in creating Car2 because this is not a function and it is not used Can not be a manufacturer nor inherited any standard object methods, it is only a placeholder for the object specified for Car2.prototype . But I think this is just an example.

    For more questions ?? |

    How is the above example correct? The above example starts refuting the example.

    How does this example conflict?

    Also, car2.desc = 'Merc' Trying to set a value does not look right.

    Setter for desc actually rawDesc , But rawDesc is set to writeable: incorrect . Change it to writeable: true and value changes But this one There is public property, by setting some other properties anyway, its value can not be determined slightly.

    Which parts of Object.defineProperty and Object.create are the same?

    and are imminent in ECMA ???? 262, it is not hard to work, in fact, first adds an asset to only one existing object, the second creates a new object and its [[prototype]] (i.e. it is a constructor Is equivalent to) sets.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -