0

When I create class in JavaScript I can define static methods outside class body. Can I actually also add definition of non-static methods?

class Class {
    fun() {console.log("some method")} //how to put it outside Class body?
}

Class.static_fun = function () {
    console.log("some static method");
}

var object = new Class();
Class.static_fun();
object.fun();
Ch3shire
  • 1,095
  • 2
  • 14
  • 39
  • 1
    I believe ```Class.static_fun``` will not be accessible from instances ```object.static_fun()``` because ```static_fun``` is not declared on the prototype – Varinder Feb 22 '18 at 20:24
  • Yes, how much do you know about how `class` works in JS? – zzzzBov Feb 22 '18 at 20:25
  • 2
    "*Can I actually also add definition of non-static methods?*" - Sure: `Class.prototype.fun = function() { … };` – Bergi Feb 22 '18 at 20:58

0 Answers0