UNPKG

mm_os

Version:

MM_OS服务端架构,用于快速构建应用程序,支持网站建设、小程序后台、AI应用、物联网(IOT/AIOT)、游戏服务端等多种场景。

43 lines (39 loc) 902 B
/** * 组件基类 */ class Component { constructor() { this._is_dirty = false; // 使用 Proxy 代理对象,拦截属性设置操作 return new Proxy(this, { set: function (target, prop, value) { if (prop === '_is_dirty') { target._is_dirty = value; return true; } if (target[prop] !== value) { target._is_dirty = true; } target[prop] = value; return true; }, get: function (target, prop) { return target[prop]; } }); } isDirty(is_dirty) { if (is_dirty !== undefined) { this._is_dirty = is_dirty; } return this._is_dirty; } } /** * 转换为JSON字符串 * @returns {string} JSON字符串 */ Component.prototype.toJson = function () { return JSON.stringify(this); }; module.exports = Component;