Skip to content

Latest commit

 

History

History
39 lines (34 loc) · 8.92 KB

bridge.md

File metadata and controls

39 lines (34 loc) · 8.92 KB

Bridge Variable Syntax Conversion Table

The table below provides some more comprehensive information on how bridge variables behave:

Syntax on Python Bridge Variable (x) in JavaScript Equivalent Python or Effect
x.attr or x['attr'] Returns x.attr first, then x['attr'] if x.attr does not exist. For more granularity, explicitly use x.__getattr__('attr') and x.__getitem__('attr').
x.attr = ... or x['attr'] = ... Sets x.attr if and only if the attribute already existed, else sets x['attr']. For more granularity, explicitly use x.__setattr__('attr', ...) and x.__setitem__('attr', ...).
'attr' in x Returns if hasattr(x, 'attr') or 'attr' in x. For more granularity, explicitly use x.__contains__('attr').
delete x.attr or delete x['attr'] del x.attr if and only if the attribute already existed, else del x['attr']. For more granularity, explicitly use x.__delattr__('attr') and x.__delitem__('attr').
x(...) Calls x(...) in Python, if x is callable.
new x(...) Constructs x(...) in Python, if x is constructable.
for (... of x) for ... in x, if x is iterable.
Object.getOwnPropertyNames(x) Returns dir(x) plus other attributes Coldbrew supports, if x is not a function or a class. Otherwise, returns something resembling Object.getOwnPropertyNames(class{}).
x.toString() Returns x.to_string() or str(x).
x.toJSON() Returns x.to_json() if defined, otherwise json.dumps(str(x)).
x.__inspect__() Returns dir(x) plus other attributes Coldbrew supports.
x.__type__ Returns the name of the Python type of x.
x.__destroy__() Signals x will no longer be used and allows x to be garbage collected.
x.__destroyed__ Returns whether x has been allowed to be garbage collected.
Syntax on JavaScript Bridge Variable (x) in Python Equivalent JavaScript or Effect
x.attr or x['attr'] Returnsx['attr'].
x.attr = ... or x['attr'] = ... Sets x['attr'].
'attr' in x Returns 'attr' in x.
len(x) Returns x.length, if length attribute exists or returns x.size or x.size(), if size attribute exists.
del x.attr or del x['attr'] delete x['attr'].
x(...) Calls x(...) in JavaScript, if x is callable or constructs new x(...) in JavaScript, if x is constructable.
for ... in x for (... of x), if x is iterable.
dir(x) Returns Object.getOwnPropertyNames(x).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(x))) plus other attributes Coldbrew supports.
str(x) Returns x.toString(), if defined, otherwise returns repr(x).
repr(x) Returns a string representation of x for debugging purposes.
x.__inspect__() Returns Object.getOwnPropertyNames(x).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(x))) plus other attributes Coldbrew supports.
x.__type__ Returns the name of the JavaScript type of x.
x.__destroy__() Signals x will no longer be used and allows x to be garbage collected. (unnecessary to use this for bridge variables in Python, GC automatically happens!)
x.__destroyed__ Returns whether x has been allowed to be garbage collected.