From 57554fa64400c4bd4503401c2a7d4adaa77396de Mon Sep 17 00:00:00 2001 From: coding Date: Sat, 14 Oct 2017 07:32:00 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=8D=E5=B0=84=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eset=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/core/reflect.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/resources/core/reflect.js b/src/main/resources/core/reflect.js index 3c66ee4..c0aa992 100644 --- a/src/main/resources/core/reflect.js +++ b/src/main/resources/core/reflect.js @@ -17,6 +17,7 @@ function Reflect(obj) { this.obj = obj; this.class = obj.class; } + this.field = function (name) { try { // Try getting a public field @@ -59,6 +60,15 @@ function Reflect(obj) { return arguments.length === 1 ? this.field(arguments[0]) : this.obj; }; + this.set = function (name, value) { + try { + this.class.getField(name).set(this.obj, value); + } catch (ex) { + accessible(this.class.getDeclaredField(name)).set(this.obj, value); + } + return this; + } + this.create = function () { var param = Array.prototype.slice.call(arguments); return on(declaredConstructor(this.class, param).newInstance(param));