1樓:德川家康薛丁格
貌似目前還不能直接在 class 裡定義,但是應該可以這麼寫。。
class
TEST
{}TEST
.prototype
.foo
="bar"
;let
test
=new
TEST
;console
.log
(test
.foo
)// "bar"
2樓:謝然
要寫的話也不是不可以,寫成原型上的getter方法就行了,就是麻煩點:
class
Aget
father()}
3樓:zidian257
你說的是例項屬性吧?
關於語法的話,ES7 有提案,如下(此提案 Babel 支援轉碼,chrome 不支援,除錯的話試試 babel-node )
class
Foo//es6支援的類的靜態方法
static
myStaticMethod()}
//es6支援的類的靜態屬性
Foo.
myStaticProp2
='Im also static property of Foo'
varfoo
=new
Foo()
Foo.
myStatic
//static
foo.
father
//me
foo.
papa
//me
foo.
myStaticMethod
()//毫無疑問找不著
Foo.
myStaticMethod
()//static method
參考:http://
4樓:
使用 ES6 的 class 語法現在還做不到你說的那種效果。
只能這樣:
People
.father
="me"
// or
class
People}
如何讓es6中class的成員函式支援IIFE?
楊健 class A constructorthis.method this.methodmethodlet state 1 return statelet a new Aconsole.log a.method console.log a.method console.log a.method 初...
ES6中array prototype fill是怎樣工作的?
魯小夫 為什麼不呢?以下摘自 ecma 262 7.0 22.1.3.6 Array.prototype.fill value start end The following steps are taken 1.Let O be ToObject this value 2.Let len be To...
在 ES6 的 Class 中,你是基於何種考量把某個 get 操作封裝成了計算屬性而不是方法?
小欣 一般get和set 一起使用,才會體現出其中的優點。class User get namedo something elsereturn this.name set name value do something elsethis.name value n const user new Use...