zvava
zvava

Reputation: 101

Method/Function Appears as Variable in IntelliSense

so I've been working on a simple thing to play around with, here is a snippet of code I made;

var person = function(first, last) {
    this.firstName = first;
    this.lastName = last;
    this.fullName = () => `${this.firstName} ${this.lastName}`;
}

Now if I type out the fullName() method of the object, it displays like this;

Hmm

Instead of displaying as a method, it displays as a variable, this also happens to the "person" object, is there any way to override the IntelliSense to get it to display properly?

Upvotes: 0

Views: 96

Answers (2)

N-ate
N-ate

Reputation: 6933

You assigned an arrow function to the property. You may be able to get the behavior you want using the new keyword. I'm not certain though my knowledge about constructors has faded since We were told to stop using them 5 years or so ago.

Upvotes: 0

Schalk
Schalk

Reputation: 133

Just small note about the difference between functions and methods:

Methods are related to Classes, while Functions are not. Since JavaScript is multi-paradigm (one of these being functional), most JavaScript functions are just that - functions. All Methods are Functions, but not all Functions are Methods.

On to your question, it has a simple answer: Lambdas (arrow notation) aren't classified as functions, so they'll display as variables/properties.

Hope this hepled!

Upvotes: 1

Related Questions