Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 934527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:00:58+00:00 2026-05-15T21:00:58+00:00

A.as : public class A { public function getFunction():Function { return function():void { if(this

  • 0
A.as : 

    public class A {

    public function getFunction():Function { 
      return function():void {
        if(this is C) {
          trace("C");
        } else {
          trace("not C");
        }
     }
  }


public function func1():void {
   var internalFunc:Function = getFunction();
   internalFunc();
 }

}

B.as : 
public class B extends A implements C {

}

In some other class :

var b:B = new B();
   B.func1();

Output is :
“Not C”

I was expecting the trace output to be
“C”

Can someone explain why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:00:58+00:00Added an answer on May 15, 2026 at 9:00 pm

    An anonymous function, if called directly, is scoped to the global object. If you trace this inside it, you will see [object global] instead of [object B], as you would, if this refered to b.

    A common workaround is using a closure:

      var self:A = this;
      return function():void {
        if(self is C) {
          trace("C");
        } else {
          trace("not C");
        }
     }
    

    Please note however, the instance-members of a class defining an anonymous function are available from within. This works, because they are resolved at compile time.

    edit in response to Amarghosh’s question:

    Yes, this points to the global object, but that doesn’t mean, you cannot access the instance members of the declaring class. This little piece of code should explain the details:

    package  {
     import flash.display.Sprite;
     public class Test extends Sprite {
      private var foo:String = "foo";
      public function Test() {
       var anonymous:Function = function ():void {
        trace(foo);//foo
        trace(this.foo);//undefined
       };
       anonymous();
      } 
     }
    }
    

    greetz
    back2dos

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the class: functions.php class buildPage { public function Set($var,$val){ $this->set->$var = $val;
Consider this class: class test { public function __set($n, $v) { echo __set() called\n;
I mean something like that: class parentClass { public function method() { echo $this->prop;
recently I found a function like this in a generic JSR245 portlet class: public
I have a similar code snippet like this class Search { public function search($for,
Lets say I have a class like this in Java: public class Function {
Function abstraction: public abstract class Function<X, Y> { abstract Y apply(X x); } max
I have my class public function convert( $title ) { $nameout = strtolower( $title
<?php class test_class { public function __construct() { } public function doLogin($username,$password) { include(connection.php);
class a { public function f(&$ref1, &$ref2) { $ref1 = 'foo'; $ref2 = 'bar';

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.