How to appoint a prototype variable



  • How do you change the prototype value from another function? My code doesn't work.

    behaviorProto.Instance = function(type, inst)
    {
        this.inst = inst;               
    };
    var behinstProto = behaviorProto.Instance.prototype;
    

    function Acts() {};

    Acts.prototype.GreedStartMoving = function ()
    {
    behinstProto.inst.x = 110; //Не работает
    behinstProto.inst.y = 110; //Не работает
    };



  • Dynamic change in prototype properties.

    Right.

    Create a prototype with properties, for example.

    var someFunction = function() { } 
    someFunction.prototype.some = "a";
    somePrototype = someFunction.prototype;
    

    Dynamic change of prototype properties.

    function changeSomeProto() {
      somePrototype.some = "b"
    }
    

    Not right.

    Create the properties of a copy of the class!

    var someFunction = function() {
      this.some = 'a'; // Это собственное свойство, а не свойство прототипа
    }
    var somePrototype = someFunction.prototype;
    

    Trying to change the properties of a class copy through a prototype, which is not possible.

    function changeSomeProto() {
      somePrototype.some = "b"; // Мы присваиваем значение не существующему свойству прототипа
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2