Question

I am trying to incorporate prototype.js's bind() function into my Flash component. I found this article by Jordan Broughs, which gave me hope. He suggested using this code snippet:

        Function.prototype.bind = function():Function {
          var __method:Function = this;
          var object:Object = arguments[0];
          return function():void {
            __method.apply(object, arguments);
          }
        }

So, I put that in my class, outside of any methods or constructors. However, when I try to call bind() on a function, I get this compiler error:

1061: Call to a possibly undefined method bind through a reference with static type Function.

Any ideas?

Was it helpful?

Solution

You're extending the Function object's prototype. It doesn't belong in a class. It's not a method of your class.

The Function object is basically a built-in type, and its prototype is sort of its base class. By extending its prototype by adding bind all objects that inherit from Function, which is all functions including the ones you defined, will have a bind method that creates a closure.

EDIT:

This question is actually a duplicate and has been answered here:

ActionScript problem with prototype and static type variables

And according to that question you have remove the :Function in order for it to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top