UNPKG

warriorjs-engine

Version:
36 lines (26 loc) 1.2 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = playerObject; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var ORIGINAL_OBJECT = exports.ORIGINAL_OBJECT = Symbol(); function playerObject() { var propertyBlacklist = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; return function (target) { Object.defineProperty(target.prototype, 'toPlayerObject', { value: function value() { var _this = this; var result = {}; var properties = [].concat(_toConsumableArray(Object.getOwnPropertyNames(this)), _toConsumableArray(Object.getOwnPropertyNames(Object.getPrototypeOf(this)))); properties.filter(function (prop) { return prop !== 'toPlayerObject' && !propertyBlacklist.includes(prop); }).forEach(function (prop) { result[prop] = typeof _this[prop] === 'function' ? _this[prop].bind(_this) : _this[prop]; }); result[ORIGINAL_OBJECT] = this; return result; } }); }; }