SelectList(items, initialopt)

An array wrapper that has a pointer to one of its items.

Constructor

new SelectList(items, initialopt)

Parameters:
Name Type Default Description
items any[]

Array of items

initialopt number 0

Initial position

Author:
Satoshi Soma (amekusa.com)
License:
Apache-2.0
Copyright 2020 Satoshi Soma

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Source:
src/scripts/SelectList.js, line 19
Example
let difficulty = new SelectList([
  'easy',
  'normal', // default
  'hard'
], 1);

Members

curr any

The current item.

Source:
src/scripts/SelectList.js, line 46

length number

A number of items.

Source:
src/scripts/SelectList.js, line 39

Methods

has(item)boolean

Whether the given item is in the list.

Parameters:
Name Type Description
item any

Item to find

Source:
src/scripts/SelectList.js, line 83
Returns:
Type:
boolean

indexOf(item)number

Returns the index of the given item.

Parameters:
Name Type Description
item any

Item to find

Source:
src/scripts/SelectList.js, line 75
Returns:

Index, or negative number if not found

Type:
number

item(index)

Returns an item by the given index.

Parameters:
Name Type Description
index number

Item index

Source:
src/scripts/SelectList.js, line 60

next(wrapopt)any

Increments the pointer.

Parameters:
Name Type Default Description
wrapopt boolean true
Source:
src/scripts/SelectList.js, line 120
Returns:

Selected item

Type:
any

onSelect(fn)

Registers a callback that is invoked on every pointer movement.

Parameters:
Name Type Description
fn function
Source:
src/scripts/SelectList.js, line 67

prev(wrapopt)any

Decrements the pointer.

Parameters:
Name Type Default Description
wrapopt boolean true
Source:
src/scripts/SelectList.js, line 110
Returns:

Selected item

Type:
any

select(item)any

Moves the pointer to the given item.

Parameters:
Name Type Description
item any

Item to find

Source:
src/scripts/SelectList.js, line 91
Returns:

Selected item

Type:
any

to(pos)any

Moves the pointer to the given index.

Parameters:
Name Type Description
pos number

Index to move to

Source:
src/scripts/SelectList.js, line 100
Returns:

Selected item

Type:
any

Licensed under the Apache License 2.0

Documentation generated by JSDoc 4.0.2 using Docolatte theme