BNS
#
BNSBNS (Binance Script) is a set of scripting languages for miniprogram. Combined with BXML, the page structure can be constructed.
#
IntroductionBNS code can be written in the <bns>...</bns>
tag in the bxml file, or in a file with a .bxs extension.
Each .bns file and <bns>...</bns>
tag is a separate module.
Each module has its own independent scope. That is, variables and functions defined in a module are private by default and invisible to other modules.
If a module wants to expose its internal private variables and functions, it can only be realized through module.exports.
There are two attributes in the <bns>...</bns>
tag, module and src, and the module attribute is required and should be unique. The src attribute is optional. If it is not specified, the content of the <bns>...</bns>
tag is used as the module code.
#
Event bindingUse the BNS function to respond to miniprogram events. Currently, it can only respond to built-in component events, and does not support custom component events. In addition to pure logic operations, BNS functions can also be accessed through the encapsulated ComponentDescriptor instance and set the class and style of the component. For interactive animation, setting the style and class is enough.
eg:
bxml:
js:
the event handler receives two parameters: e and instance.
- e is Event Target, same as the event object in the miniprogram event binding function.
- instance is the ComponentDescriptor instance of the current component, which can be used to set the class and style of the component. now, only two methods are supported, setClass and setStyle.