From a5f78e7a93555a83b7eb4cb2abca0422684fd82a Mon Sep 17 00:00:00 2001 From: KingZ Date: Tue, 4 Jun 2019 10:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=AF=E5=91=80=EF=BC=8C=E9=82=A3=E5=B0=B1?= =?UTF-8?q?=E6=B2=A1=E5=BE=97=E9=97=AE=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/ask-my-object.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 js/ask-my-object.js diff --git a/js/ask-my-object.js b/js/ask-my-object.js new file mode 100644 index 0000000..a24f155 --- /dev/null +++ b/js/ask-my-object.js @@ -0,0 +1,35 @@ +class Person { + get object() { + return this.myObject; + } + set object(val) { + this.myObject = val; + } + borrowMoney(amount) { + console.log(`\r\n借${amount}块钱`); + console.log(`得先问问我对象`); + const suggestion = this.askMyObject(); + if (suggestion) { + console.log('...') + console.log('我对象说,你说啥?'); + } else { + console.log('你不是没有对象吗'); + console.log('是呀,那就没得问了'); + } + } + askMyObject() { + if (Object.prototype.toString.call(this.object) === '[object Object]') { + return true; + } else { + return false; + } + } +} +const me = new Person(); +me.borrowMoney(1000) + +const you = new Person(); +you.object = { + weight: '500斤的瘦子' +}; +you.borrowMoney(1000) \ No newline at end of file -- Gitee