when you define a static property in the class its bind it to the constructor so when you do new Repo() the return value not containing the static method but new Repo().constructor will contain the static methods
let newRepo = new Repo({yeah: 'baby'});
Repo.key // defined
newRepo.key // not defined
newRepo.constructor.key // defined
and another thing: the Repo.key === newRepo.constructor.key. So by creating a static property (like in other language such as c#) the property lives once in the scope, but this is a completely different issue :)
EDIT:
The reason that your code isn't working is because you are using a get property as a function.
By putting the set key before a function property you are setting the function to be a set property... that means that the function is been set a get on Object.definePropery
Lets look at the convert es6 using babel
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Repo = function () {
function Repo() {
var someParam = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
_classCallCheck(this, Repo);
this.getDic = someParam;
}
_createClass(Repo, null, [{
key: 'key',
value: function key(_key) {
console.log(this.constructor.getDic);
return this.getDic[_key];
}
}, {
key: 'getDic',
set: function set(ref) {
this.ref = ref;
},
get: function get() {
return this.ref;
}
}]);
return Repo;
}();
var newRepo = new Repo({ yeah: 'baby' });
Repo.key('yeah'); // Uncaught TypeError: Cannot read property 'yeah' of undefined
To make a long story shot just use Repo.key = 'heya' and you are good to go.
staticdoes?Repo, not onnewRepo(as you have now edited in). You most likely just don't want to usestaticat all.