Skip to content

this keyword in functions in objects are converted to undefined #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MaddyUnderStars opened this issue Apr 13, 2025 · 1 comment · May be fixed by #257
Open

this keyword in functions in objects are converted to undefined #256

MaddyUnderStars opened this issue Apr 13, 2025 · 1 comment · May be fixed by #257

Comments

@MaddyUnderStars
Copy link

MaddyUnderStars commented Apr 13, 2025

Running the following through hsm

export default function(context, args) {
    const a = {
        b: function() {
            return this;
        },
    }

    return a.b();
}
}

produces the below

function(context, args) {
  let a = {
    b: function () {
      return undefined
    }
  }
  return a.b()
}

notice the conversion of this to undefined. this in b should refer to a

This issue seems very closely related to #236

@MaddyUnderStars MaddyUnderStars changed the title this keyword in keyword functions in objects are converted to undefined this keyword in functions in objects are converted to undefined Apr 13, 2025
@samualtnorman
Copy link
Owner

thank you for this bug report! as a workaround for now, you can do

function (context, args) {
	const a = {
		b() {
			return this
		}
	}
}

which should be the equivalent (except that it works)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants