dart:core 庫中Symbol構造函數 的用法介紹如下。
用法:
const
Symbol(
String name
)
構造一個新的 Symbol 表示提供的名稱。
從相等的name 字符串創建的符號本身是相等的。如果使用 const 創建符號,則具有相同 name 字符串的符號將被規範化且相同。
一些 name 字符串創建的符號也可以使用符號文字創建,或者在運行 Dart 程序時隱式創建,例如通過 Object.noSuchMethod 。
如果name是一個不以下劃線開頭的單個 Dart 標識符,或者它是一個限定標識符(多個標識符由.s),或者它是用戶可定義運算符的名稱,不同於unary-(其中之一“+", "-", "*", "/", "%", "~/", "&", "|", "^", "~", "<<", ">>", ">>>", "<", "<=", ">", ">=", "==", "[]“, 或者 ”[]="),那麽結果Symbol(name)等於通過前綴創建的符號文字#對內容name, 和const Symbol(name)與該符號文字相同。那是#foo == Symbol("foo")和identical(#foo, const Symbol("foo")).
如果 name 是單個標識符,不以下劃線開頭,後跟 = ,則該符號是一個設置器名稱,並且可以等於 Object.noSuchMethod 調用中的 Invocation.memberName。
私有符號文字,如 #_foo ,不能使用符號構造函數創建。像 const Symbol("_foo") 這樣的符號不等於任何符號文字,也不等於 noSuchMethod 引入的任何源名稱符號。
assert(Symbol("foo") == Symbol("foo"));
assert(Symbol("foo") == #foo);
assert(identical(const Symbol("foo"), const Symbol("foo")));
assert(identical(const Symbol("foo"), #foo));
assert(Symbol("[]=") == #[]=]);
assert(identical(const Symbol("[]="), #[]=));
assert(Symbol("foo.bar") == #foo.bar);
assert(identical(const Symbol("foo.bar"), #foo.bar));
創建的實例覆蓋 Object.== 。
相關用法
- Dart StreamTransformer構造函數用法及代碼示例
- Dart SplayTreeSet.lookup用法及代碼示例
- Dart String.replaceAll用法及代碼示例
- Dart Stream.fromFutures用法及代碼示例
- Dart StreamController用法及代碼示例
- Dart StringList.first用法及代碼示例
- Dart Stream.fold用法及代碼示例
- Dart SetMixin.forEach用法及代碼示例
- Dart SetMixin.addAll用法及代碼示例
- Dart Stream.map用法及代碼示例
- Dart String.fromCharCodes用法及代碼示例
- Dart Set.removeWhere用法及代碼示例
- Dart Set.from用法及代碼示例
- Dart StreamSubscription用法及代碼示例
- Dart SplayTreeMap.from用法及代碼示例
- Dart SetMixin.reduce用法及代碼示例
- Dart String.trim用法及代碼示例
- Dart Set.remove用法及代碼示例
- Dart Set.retainAll用法及代碼示例
- Dart String.lastIndexOf用法及代碼示例
- Dart SourceBufferList.first用法及代碼示例
- Dart String.replaceRange用法及代碼示例
- Dart StringList.length用法及代碼示例
- Dart SetMixin.removeAll用法及代碼示例
- Dart SetMixin.add用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 Symbol constructor。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
