Function.apply not using thisArg parameter

后端 未结 4 1061
遇见更好的自我
遇见更好的自我 2020-12-16 20:48

I\'m writing some Actionscript3 code that attempts to apply a method to an object that is determined at runtime. The AS3 documentation for Function.apply and Function.call b

4条回答
  •  借酒劲吻你
    2020-12-16 20:57

    Have you tried actually using the this reference explicitly, i.e.:

    internal class MyObj
    {
        private var _name:String;
        public function MyObj(name:String)
        {
            _name = name;
        }   
        public function sayName():void
        {
            trace(this._name);
        }
    }
    

    It might just be that when the this keyword is omitted, the original instance is used to look up the field/variable, whereas what thisArg really does is to re-bind the this keyword. If that's the case it's arcane at best, but it might be worth a try.

提交回复
热议问题