Difference between Class.method and Class.prototype.method Last Updated : 18 Jan, 2023 Comments Improve Suggest changes Like Article Like Report JavaScript is an object-oriented programming language, but unlike its peers (which are class-based), JavaScript is a prototype-based language. It means that in JavaScript, you can create an object (prototype object) that acts as a template for new objects. These new objects can be provided with new properties either when you create them or at run time. There are two ways to add new methods to an object. Class.method: The Class.method is static and has no relation with any instance of the class. The class method must be called using the class name. Only one instance of this function exists in the memory. Example: This example shows the use of the above-explained method. JavaScript <script> // Constructor function function User(userName) { this.userName = userName; }; // Static function User.message = function () { console.log("Login successful"); }; // Creating an instance of User // using new keyword const newUser = new User("GFG"); // Message method accessed with User User.message(); </script> Output: Login successful Class.prototype.method: The Class.prototype.method is created which is related to the instance of the object. It is called using the object instance name. Each instance of the class will have its own copy of this method. Example: This example shows the use of the above-explained method. JavaScript <script> function User(userName) { this.userName = userName; }; User.message = function () { console.log("Login successful"); }; // Instance method User.prototype.greet = function () { // can access object properties // using 'this' keyword console.log("Welcome " + this.userName); }; const newUser = new User("GFG"); User.message(); // Instance method being accessed // using instance variable newUser.greet(); </script> Output: Login successful Welcome GFG The above code can be written using JavaScript classes that were introduced in ECMAScript 2015. JavaScript <script> // JavaScript class class User { constructor(userName) { this.userName = userName; } // Corresponds to User.message() static message = function () { console.log("Login successful"); }; // Corresponds to User.prototype.greet() greet = function () { console.log("Welcome " + this.userName); }; } const newUser = new User("GFG"); User.message(); newUser.greet(); </script> Output: Login successful Welcome GFG JavaScript classes are syntactical sugar over JavaScript's prototype-based approach. Comment More infoAdvertise with us Next Article Difference between Class.method and Class.prototype.method sareendivyansh Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads Difference between proto and prototype In this article, we will be going to cover the topic what is proto and prototypes, their syntax, examples, and what are differences exist between both, and how they differ and how they differ in different aspects. Proto and prototype both are objects that help in whether creating an array, object, 3 min read Differences between ES6 class and ES5 function constructors In this article, we will discuss the difference between the ES6 class and ES5 function constructors. Both serve the purpose of creating new objects, still, they have some differences between them. ES6 Class constructors: ES6 class constructors work quite the same as class constructors in other objec 2 min read Difference Between Objects and Prototypes in JavaScript Objects in JavaScriptThe Objects in JavaScript are instances of the class or constructors and they can hold properties and methods. These properties and methods can be unique to the object or inherited from the prototypes. The Objects can be created using the constructor functions, object literals, 3 min read Difference between Function.prototype.apply and Function.prototype.call JavaScript treats everything as an object, even functions, and every object has its own properties and methods. Function objects have both apply() and call() methods on them. However, there is confusion about the two functions in JavaScript. The main difference between them is how they handle functi 2 min read Difference between interfaces and classes in TypeScript In this article, we will see what is the Difference between "interface" and "Classes" in TypeScript. Interface: Interface is the virtual structure that is used for type-checking. In TypeScript we use interface keyword to create the new interface with identity. It create the structure for the same da 3 min read Difference Between instanceof and isPrototypeOf() in JavaScript In JavaScript, understanding object relationships and type checks is crucial for the effective programming. The Two methods that facilitate these checks are instanceof and isPrototypeOf(). While both are used to the determine the type or prototype relationships in the JavaScript they operate differe 2 min read What is difference between CoffeeScript and ES6 ? CoffeeScript is just like JavaScript is a lightweight language that compiles into JavaScript. It provides simple and easy-to-learn syntax avoiding the complex syntax of JavaScript. CoffeeScript is influenced by JavaScript, Ruby, YAML, Haskell, Perl, and Python and has influenced MoonScript, LiveScri 2 min read Difference between ES5 and ES6 ECMAScript (ES) is a standardized scripting language specification developed by Ecma International. It serves as the foundation for JavaScript and many other scripting languages. Over time, different versions of ECMAScript have been released, with ES5 (ECMAScript 5) and ES6 (ECMAScript 6) being two 3 min read Difference between First-Class and Higher-Order Functions in JavaScript Understanding the difference between first-class and higher-order functions in JavaScript is important. These are big concepts in programming, especially in the kind of coding used for making websites. This article is all about explaining what they are, how they are used, and why they are so importa 3 min read What's the Difference Between 'extends' and 'implements' in TypeScript ? TypeScript offers powerful way for organizing code and managing relationships between different components through the use of extends and implements keywords. This article explores the distinctions and functionalities of these two keywords.ExtendsThe extends keyword is used for two main purposes in 2 min read Like