Last active
July 13, 2018 18:44
-
-
Save mmis1000/3025eaad2d39a035a016d49ab42f26f5 to your computer and use it in GitHub Desktop.
some thougt about the proposal-private-methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 0 current proposal | |
// 1 this proposal | |
// 2 polyfilled | |
/* 2 */ const class_a_private_priv = Symbol('priv') | |
/* 2 */ const class_a_private_someSecretMethod = Symbol('someSecretMethod') | |
/* 2 */ const class_a_private_privProxy = Symbol('privProxy') | |
class a() { | |
/* 0 */ #priv = 0; | |
/* 1 */ private priv = 0; | |
/* 2 */ constructor() { this[class_a_private_priv] = 0; } | |
set(val) { | |
/* 0 */ #priv = val; | |
/* 1 */ private.priv = val; | |
/* 2 */ this[class_a_private_priv] = val; | |
} | |
get(val) { | |
/* 0 */ return #priv; | |
/* 1 */ return private.priv; | |
/* 2 */ return this[class_a_private_priv]; | |
} | |
equal(that) { | |
/* 0 */ return #priv === that.#priv | |
/* 1 */ return private.priv === private(that).priv | |
/* 2 */ return this[class_a_private_priv] === that[class_a_private_priv]; | |
} | |
someMethodThatWillCallOurSecretMethod() { | |
/* 0 */ #someSecretMethod(); | |
/* 1 */ private.someSecretMethod(); | |
/* 2 */ this[class_a_private_someSecretMethod](); | |
} | |
/* 0 */ #someSecretMethod() {} | |
/* 1 */ private someSecretMethod() {} | |
/* 2 */ [class_a_private_someSecretMethod]() {} | |
/* 0 */ get #privProxy () { return #priv; } | |
/* 0 */ set #privProxy (value) { #priv = value; } | |
/* 1 */ private get privProxy () { return private.priv; } | |
/* 1 */ private set privProxy (value) { private.priv = value; } | |
/* 2 */ get [class_a_private_privProxy] () { return this[class_a_private_priv]; } | |
/* 2 */ set [class_a_private_privProxy] (value) { this[class_a_private_priv] = value; } | |
/* 0 */ static compare(a, b) { return a#priv === b#priv; } | |
/* 1 */ static compare(a, b) { return private(a).priv === private(b).priv; } | |
/* 2 */ static compare(a, b) { return a[class_a_private_priv] === b[class_a_private_priv]; } | |
anotherMethod(that, privateFieldName) { | |
/* 0 */ ??? | |
/* 1 */ retrun private(that)[privateFieldName]; | |
/* 2 */ ??? | |
} | |
} | |
/* | |
the private(that)[privateFieldName] does not have any equivalent in current proposal | |
so it seems it introduced new behavior to the proposal | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment