Skip to content

In JS, function declarations should allow subsequent prototype assignment #23007

Description

// @allowJs: true// @checkJs: true// @Filename: a.jsfunctionC(p){this.p=p}C.prototype={m(){console.log(this.p)}}C.prototype.q=function(r){returnthis.p===r}varc=newC(1)c.q(2)c.m()

Expected behavior:
Both q and m are methods on c.

Actual behavior:
Only q is a method on c; m is not recognised.

Note that if the declaration is var C = function(p) { this.p = p }, everything works. This only happens when C is a function declaration instead of a variable declaration with a function initialiser.

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specifically

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions