Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@sandersn

Description

@sandersn
Issue body actions
// @allowJs: true
// @checkJs: true
// @Filename: a.js
function C(p) {
  this.p = p
}
C.prototype = {
  m() {
    console.log(this.p)
  }
}
C.prototype.q = function(r) {
  return this.p === r
}
var c = new C(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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallyThe issue relates to JavaScript specifically

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.