javascript - Function expressions not updating values, functions beeing called only once (module) -
So basically this I want a way to update the function's values, so when it changes from another function, it still works correctly. Here's what I mean:
function PropellingNozzle (power) {this.power = power; This.afterburner = "off"; Function acceleration (afterburner, power) {this. Afterburner = afterburner; Console.log (this.power); If (this. Afterburner == "on") {this.acceleration = this.power * 2; } And if (this is later) = "Off") {this.acceleration = this.power; } Console.log ("called"); Come back it Delegation} return {electricity: this.power, afterburner: this.afterburner, switch, afterburner: function () (if (this.afterburner == "off") {this.afterburner = "on";} and if (this. Afterburner = = "On") {this.afterburner = "off";}}, acceleration: acceleration (this is later, this.power)}}
As you can see, I know that values have been started parsing and what not, just experimenting and it still does not work. In Jsfiddle the whole code is part of the test with prefrebly, switchAfterburner also be in PropellingNozzle function But if this can not work, there is no problem in returning. My job is to write the code as possible in the form of the object with my knowledge so far
You are only calling once when specifying a value for acceleration
property Whenever one of the values changes, you are not assigning function expression to evaluate again, lek And you are specifying the result value of it.
So what to do against it? You can update
-
acceleration
property, when any value depends on the changes. When they are set by your functions only (such asswitchAfterBurner
) and are not explicitly specified from the outside, it is easy to re-calculate within those sets. - Instead of reading a property for acceleration, instead of reading a property, call out a
getAcceleration ()
function that dynamically calculates the correct value.
Btw, please
function preening gunz (power) {this.power = power; This.afterburner = "off"; This. SwitchAfterburner = function () {...}; ...} var example = new propelling nozzle (...); (Power), afterburner: "off", switchAfterburner: function () {...},
or
function makePropellingNozzle (power) .. .}} } Var example = makePropellingNozzle (...);
But there is no mix of both.
Comments
Post a Comment