[Basic Type](../groups/Basic Type.Basic Type.md) / Action
Action Class
agent
Proxy is a design mode that allows you to create an intermediate object to control access to another object.
How does an agent work?
The editor has encapsulated the proxy function, which may be different from the proxy method you used before, but this method may be more convenient for you.
add Method to add specific transactions that require proxy.
call Method execution proxy.
Why use a proxy?
Agents can act as gatekeepers to control and restrict access to objects. It can verify the authority of the caller, restrict access to sensitive operations, or record access log. Proxy mode allows you to enhance the security of the original object without change it.
The proxy object can be responsible for create or initializing the real object on the first access, and redirecting subsequent access to the create object.
wait...
How to understand agents in a simple and understandable way?
Assuming you are a busy company owner, you need to handle many tasks, including communicating with clients, signing documents, and so on. However, due to your limited time, you are unable to personally handle all the affairs. So you decided to hire an assistant to help you handle these affairs. This assistant is your agent.
The agent (assistant) has the same ability and responsibility as you. He can communicate with customers and sign file on your behalf. When there is a transaction to be processed, you delegate the task to an agent, who will perform related operations on your behalf. However, agents do not completely replace your existence. Although agents can handle most transactions, in some cases, they need to delegate tasks to you for processing. For example, when encountering special requests or requiring your personal decisions, the agent will return the task to you.
Example usage: Create a script called ActionExample, place it in the object bar, open the script, enter the following code to save, run the game, press keyboard "1" to see the effect of the agent being called, press keyboard "2" to see the effect of the agent being removed, the code is as follows:
Hierarchy
Table of contents
Accessors
count(): number other |
---|
The number of monitoring methods |
Methods
add(fn : Function , thisArg? : any ): number other |
---|
Add a listening method |
call(...params : any ): void other |
implement |
clear(): void other |
Clear all listening |
includes(fn : Function , thisArg : any ): boolean other |
Determine whether a certain listening method is included |
remove(fn : number Function , thisArg? : any ): void other |
Remove a listening method |
Accessors
count
• |
---|
The number of monitoring methods Returns |
number |
---|
Methods
add
• add(fn
, thisArg?
): number
other
Add a listening method
Parameters
fn Function | method |
---|---|
thisArg? any | Domain, the following example can explain the concept of domain default: undefined |
Returns
number | The unique identifier for this monitoring can be used for removal. If -1 is returned, it indicates that this method has been added before and will not be added again. |
---|
Usage example: Explain the concept of "domain"
call
• call(...params
): void
other
implement
Parameters
...params any | Parameter sequence |
---|
Example usage: Create a script called ActionExample, place it in the object bar, open the script, enter the following code to save, run the game, press keyboard "1" to see the effect of the agent being called, press keyboard "2" to see the effect of the agent being removed, the code is as follows:
clear
• clear(): void
other
Clear all listening
includes
• includes(fn
, thisArg
): boolean
other
Determine whether a certain listening method is included
Parameters
fn Function | method |
---|---|
thisArg any | field |
Returns
boolean | result |
---|
remove
• remove(fn
, thisArg?
): void
other
Remove a listening method
Parameters
fn number Function | Method Monitor unique identifier |
---|---|
thisArg? any | Domain default: undefined |