
- ES6 教程
- ES6 - 首頁
- ES6 - 概述
- ES6 - 環境
- ES6 - 語法
- ES6 - 變數
- ES6 - 運算子
- ES6 - 決策
- ES6 - 迴圈
- ES6 - 函式
- ES6 - 事件
- ES6 - Cookie
- ES6 - 頁面重定向
- ES6 - 對話方塊
- ES6 - Void 關鍵字
- ES6 - 頁面列印
- ES6 - 物件
- ES6 - 數字
- ES6 - 布林值
- ES6 - 字串
- ES6 - Symbol
- ES6 - 新的字串方法
- ES6 - 陣列
- ES6 - 日期
- ES6 - 數學
- ES6 - 正則表示式
- ES6 - HTML DOM
- ES6 - 迭代器
- ES6 - 集合
- ES6 - 類
- ES6 - Map 和 Set
- ES6 - Promise
- ES6 - 模組
- ES6 - 錯誤處理
- ES6 - 物件擴充套件
- ES6 - Reflect API
- ES6 - Proxy API
- ES6 - 驗證
- ES6 - 動畫
- ES6 - 多媒體
- ES6 - 除錯
- ES6 - 圖片地圖
- ES6 - 瀏覽器
- ES7 - 新特性
- ES8 - 新特性
- ES9 - 新特性
- ES6 有用資源
- ES6 - 快速指南
- ES6 - 有用資源
- ES6 - 討論
ES6 - Reflect.get()
這是一個返回屬性值的函式。
語法
下面給出該函式get()的語法,其中:
target 是要獲取屬性的目標物件。
propertyKey 是要獲取的屬性的名稱。
Receiver 是如果遇到 getter,則為對 target 的呼叫提供的 this 值。這是一個可選引數。
Reflect.get(target, propertyKey[, receiver])
示例
下面的示例使用反射建立 Student 類的例項,並使用Reflect.get() 方法獲取例項的屬性。
<script> class Student{ constructor(firstName,lastName){ this.firstName = firstName this.lastName = lastName } get fullName(){ return `${this.firstName} : ${this.lastName}` } } const args = ['Tutorials','Point'] const s1 = Reflect.construct(Student,args) console.log('fullname is ',Reflect.get(s1,'fullName')) console.log('firstName is ',Reflect.get(s1,'firstName')) </script>
上面程式碼的輸出將如下所示:
fullname is Tutorials : Point firstName is Tutorials
廣告