AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

at

描述

at 方法用于返回在指定时间后执行的回调函数。该函数可以被多次调用,每次都会返回一个唯一 id,可以用于取消回调函数的执行。

语法

const id = at(callback, delay[, param1[, param2[, ...]]]);

参数

  • callback:要执行的回调函数。
  • delay:延迟时间,以毫秒为单位。
  • param1, param2, ...:传递给回调函数的参数。

返回值

返回一个唯一的 id

示例

const id1 = at(() => console.log('one'), 1000);
const id2 = at((val) => console.log('two', val), 2000, 'hello');
const id3 = at(() => console.log('three'), 3000);

clearAt(id1); // 取消延迟 1000ms 后执行的回调函数

function clearAt(id) {
  clearTimeout(id);
  console.log(`clearAt: ${id}`);
}

注意事项

  • 如果未传入参数,则回调函数将在延迟结束后被调用。
  • 如果要取消回调函数的执行,可以使用 clearTimeout 方法,并将 id 作为参数传入。