---
title: MAIN
project: jComponent V20
version: 20.015
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-015/reference/main/
updated: 2026-11-18T13:58:14.460Z
---

# MAIN

> The main object of the library, with its state and its low-level methods.

`MAIN` is the main object of the library. `M`, `Total` and `jComponent` are other names for the same object. It holds the state of the library and low-level methods that work with any scope. For everyday code, use the [global functions](../globals/) described with [Paths](../../guides/paths/).

## API

### MAIN.Binder

Type: `class`

The class of data bindings.

See [ui-bind](../ui-bind/).

### MAIN.binders

Type: `property`

The active data bindings.

Returns: `Array` The active data bindings.

See [ui-bind](../ui-bind/).

### MAIN.caller

Type: `property`

The plugin that was last called through `EXEC()`.

Returns: `Plugin` The plugin that was last called through `EXEC()`.

Example: Read the caller
```html
<ui-plugin path="users"></ui-plugin>

<script>
PLUGIN('users', function(self) {
	self.refresh = NOOP;
});

ON('ready', function() {
	EXEC('users/refresh');
	console.log(MAIN.caller.name); // users
});
</script>
```

### MAIN.cl(name, [callback])

Type: `method`

The same function as `CL()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The names of the code lists. |
| `callback` | `Function` | no |  | A function that runs when the lists are loaded. |

See [CL()](../globals/).

### MAIN.Component

Type: `class`

The class of components.

See [Component](../component/).

### MAIN.components

Type: `property`

The active component instances.

Returns: `Array` The active component instances.

See [Component](../component/).

Example: Count the components
```html
<ui-component name="box"></ui-component>

<script>
COMPONENT('box', function(self) {});

ON('ready', function() {
	console.log(MAIN.components.length); // 1
});
</script>
```

### MAIN.data

Type: `property`

The storage of plugins with a generated path.

Returns: `Object` The storage of plugins with a generated path.

See [DEF.path](../def/).

### MAIN.def

Type: `property`

The same object as `DEF`.

Returns: `Object` The same object as `DEF`.

See [DEF](../def/).

Example: Compare the objects
```js
console.log(MAIN.def === DEF); // true
```

### MAIN.emit(name, [a], [b], [c], [d])

Type: `method`

The same function as `EMIT()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `a` | `Object` | no |  | The first argument. |
| `b` | `Object` | no |  | The second argument. |
| `c` | `Object` | no |  | The third argument. |
| `d` | `Object` | no |  | The fourth argument. |

See [EMIT()](../globals/).

### MAIN.events

Type: `property`

The global event handlers, by event name.

Returns: `Object` The global event handlers, by event name.

See [Events](../events/).

### MAIN.exec(name, [a], [b], [c], [d])

Type: `method`

Runs the same logic as `EXEC()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The target of the call. |
| `a` | `Object` | no |  | The first argument. |
| `b` | `Object` | no |  | The second argument. |
| `c` | `Object` | no |  | The third argument. |
| `d` | `Object` | no |  | The fourth argument. |

See [EXEC()](../globals/).

### MAIN.find(scope, path, callback)

Type: `method`

Finds the components of a path in a scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The scope, usually `window`. |
| `path` | `String` | yes |  | The path, optionally with flags. |
| `callback` | `Function` | yes |  | A function that receives the array of components. |

Flags in the path narrow the result: `@visible`, `@touched`, `@modified`, `@required`, `@invalid`, `@disabled` and `@enabled`.

Example: Find components
```html
<ui-component name="field" path="form.name"></ui-component>

<script>
COMPONENT('field', function(self) {});

ON('ready', function() {
	MAIN.find(window, 'form', function(components) {
		console.log(components.length); // 1
	});
});
</script>
```

### MAIN.flags(flags, [callback])

Type: `method`

The same function as `FLAGS()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `flags` | `String` | yes |  | The flags. |
| `callback` | `Function` | no |  | A function that runs afterwards. |

See [FLAGS()](../globals/).

### MAIN.free()

Type: `method`

The same function as `FREE()`.

See [FREE()](../globals/).

### MAIN.get(scope, path)

Type: `method`

Reads a value from any object by a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The object to read from. |
| `path` | `String` | yes |  | The path inside the object. |

Returns: `Object` The value.

Example: Read a nested value
```js
var data = { user: { name: 'Peter' } };
console.log(MAIN.get(data, 'user.name')); // Peter
```

### MAIN.is20

Type: `property`

Identifies the major version of the library.

Returns: `Boolean` Identifies the major version of the library.

The value is always `true`.

Example: Read the value
```js
console.log(MAIN.is20); // true
```

### MAIN.loaded

Type: `property`

Becomes `true` when the persistent cache is loaded.

Returns: `Boolean` Becomes `true` when the persistent cache is loaded.

### MAIN.newbinder(element, path, config, [callback])

Type: `method`

Creates a data binding on an element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | The element. |
| `path` | `String` | yes |  | The path. |
| `config` | `String` | yes |  | The binding commands. |
| `callback` | `Function` | no |  | A function that runs when the binding is created. |

See [NEWUIBIND()](../globals/).

### MAIN.newcomponent(element, name, path, config, [callback])

Type: `method`

Creates a component on an element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | The element. |
| `name` | `String` | yes |  | The name of the component. |
| `path` | `String` | yes |  | The path. |
| `config` | `String` | yes |  | The configuration. |
| `callback` | `Function` | no |  | A function that runs when the component is created. |

Example: Create a component from code
```html
<div id="target"></div>

<script>
COMPONENT('box', function(self) {
	self.make = function() {
		console.log(self.path.path); // form.name
	};
});

ON('ready', function() {
	MAIN.newcomponent($('#target'), 'box', 'form.name', '');
});
</script>
```

### MAIN.newimporter(element, path, config)

Type: `method`

Imports content into an element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | The element. |
| `path` | `String` | yes |  | The address. |
| `config` | `String` | yes |  | The configuration of the import. |

It works like the [ui-import](../ui-import/) element.

Example: Import a part
```html
<div id="target"></div>

<script>
ON('ready', function() {
	MAIN.newimporter($('#target'), '/parts/menu.html', '');

	setTimeout(function() {
		console.log($('#target').html()); // <b>Menu</b>
	}, 400);
});
</script>
```

### MAIN.newplugin(element, path, config, [callback])

Type: `method`

Creates a plugin on an element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | The element. |
| `path` | `String` | yes |  | The name of the plugin. |
| `config` | `String` | no |  | The configuration. |
| `callback` | `Function` | no |  | A function that runs when the plugin is created. |

Example: Create a plugin from code
```html
<div id="target"></div>

<script>
PLUGIN('users', function(self) {
	self.make = function() {
		console.log(self.name); // users
	};
});

ON('ready', function() {
	MAIN.newplugin($('#target'), 'users');
});
</script>
```

### MAIN.notify(scope, path, [onlyflags])

Type: `method`

Notifies the observers of a path in a scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The scope, usually `window`. |
| `path` | `String` | yes |  | The path, optionally with flags. |
| `onlyflags` | `Boolean` | no | `false` | Limits the notification to the state of components. |

With `onlyflags`, components only refresh their state, and watchers do not run.

Example: Notify a path
```js
WATCH('total', function(value) {
	console.log(value); // 5
});

window.total = 5;
MAIN.notify(window, 'total');
```

### MAIN.off(name, [callback])

Type: `method`

The same function as `OFF()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `callback` | `Function` | no |  | The handler to remove. |

See [OFF()](../globals/).

### MAIN.on(name, callback, [init])

Type: `method`

The same function as `ON()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the event. |
| `callback` | `Function` | yes |  | The handler. |
| `init` | `Boolean` | no | `false` | Also calls the handler once. |

See [ON()](../globals/).

### MAIN.parse(type, value, [format])

Type: `method`

Converts a value to a type.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | The type. |
| `value` | `Object` | yes |  | The value. |
| `format` | `String` | no |  | The format of a date. |

Returns: `Object` The converted value.

The types are `number`, `currency`, `float`, `boolean`, `bool`, `date` and `datetime`. Numbers follow [DEF.thousandsseparator](../def/) and [DEF.decimalseparator](../def/), and dates use [DEF.dateformat](../def/) when `format` is not set. A value that cannot be converted returns `null`. Other types return the value as it is.

Example: Convert values
```js
console.log(MAIN.parse('number', '1 200.5')); // 1200.5
console.log(MAIN.parse('boolean', 'yes')); // true
console.log(MAIN.parse('date', '2024-03-01') instanceof Date); // true
```

### new MAIN.Path(path)

Type: `class`

The class that parses paths.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path, optionally with flags. |

See [Path](../path/).

Example: Parse a path
```js
var path = new MAIN.Path('form.name @change');
console.log(path.path); // form.name
console.log(path.flags); // {"change":1}
```

### MAIN.Plugin

Type: `class`

The class of plugins.

See [Plugin](../plugin/).

### MAIN.plugins

Type: `property`

The same object as `PLUGINS`.

Returns: `Object` The same object as `PLUGINS`.

See [PLUGINS](../globals/).

### MAIN.process(scope, value, target)

Type: `method`

Delivers a value to a function or a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The scope of a path. |
| `value` | `Object` | yes |  | The value. |
| `target` | `Function|String` | yes |  | A function or a path. |

A function receives the value. A path is written and notified in the scope.

Example: Deliver a value to a path
```js
MAIN.process(window, 5, 'stats.total');
console.log(GET('stats.total')); // 5
```

### MAIN.ready

Type: `property`

Becomes `true` when the library has started.

Returns: `Boolean` Becomes `true` when the library has started.

Example: Check the state
```js
ON('ready', function() {
	console.log(MAIN.ready); // true
});
```

### MAIN.resize()

Type: `method`

Measures the window again.

The method updates [WW](../globals/) and [WH](../globals/). When the size has changed, it updates the device class on the body and emits the `resize2` [event](../events/).

### MAIN.root

Type: `property`

The `window` object, which is the scope of global paths.

Returns: `Object` The `window` object, which is the scope of global paths.

Example: Compare the objects
```js
console.log(MAIN.root === window); // true
```

### MAIN.scrollbars

Type: `property`

The active custom scrollbars.

Returns: `Array` The active custom scrollbars.

See [SCROLLBAR()](../globals/).

### MAIN.seex(name, [a], [b], [c], [d])

Type: `method`

Runs the same logic as `SEEX()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The target. |
| `a` | `Object` | no |  | The first argument. |
| `b` | `Object` | no |  | The second argument. |
| `c` | `Object` | no |  | The third argument. |
| `d` | `Object` | no |  | The fourth argument. |

See [SEEX()](../globals/).

### MAIN.set(scope, path, value)

Type: `method`

Writes a value to any object by a path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | The object to write to. |
| `path` | `String` | yes |  | The path inside the object. |
| `value` | `Object` | yes |  | The value. |

Missing objects along the path are created. Nothing is notified.

Example: Write a nested value
```js
var data = {};
MAIN.set(data, 'user.name', 'Peter');
console.log(data); // {"user":{"name":"Peter"}}
```

### MAIN.setter(element, name, [a], [b], [c], [d])

Type: `method`

Runs `SETTER()` for the components inside an element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery|Plugin` | yes |  | The element or the plugin that limits the search. |
| `name` | `String` | yes |  | The selector and the method. |
| `a` | `Object` | no |  | The first argument. |
| `b` | `Object` | no |  | The second argument. |
| `c` | `Object` | no |  | The third argument. |
| `d` | `Object` | no |  | The fourth argument. |

Use `null` for all components. See [SETTER()](../globals/).

Example: Limit a call to an element
```html
<div id="a"><ui-component name="box"></ui-component></div>
<div id="b"><ui-component name="box"></ui-component></div>

<script>
COMPONENT('box', function(self) {
	self.mark = function() {
		console.log(self.element.parent().attr('id')); // a
	};
});

ON('ready', function() {
	MAIN.setter($('#a'), 'box/mark');
});
</script>
```

### MAIN.ua

Type: `property`

The detected environment: `os`, `browser` and `device`.

Returns: `Object` The detected environment: `os`, `browser` and `device`.

The `device` is `desktop`, `tablet`, `mobile` or `tv`. The value is available from the `ready` event onward.

Example: Read the device
```js
ON('ready', function() {
	console.log(Object.keys(MAIN.ua)); // ["os","browser","device"]
});
```

### MAIN.unwatch(path, [callback])

Type: `method`

The same function as `UNWATCH()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |
| `callback` | `Function` | no |  | The watcher to remove. |

See [UNWATCH()](../globals/).

### MAIN.version

Type: `property`

The version of the library.

Returns: `Number` The version of the library.

Example: Read the version
```js
console.log(MAIN.version); // 20.015
```

### MAIN.watch(path, callback, [init])

Type: `method`

The same function as `WATCH()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | The path. |
| `callback` | `Function` | yes |  | The watcher. |
| `init` | `Boolean` | no | `false` | Also calls the watcher once. |

See [WATCH()](../globals/).

### MAIN.watchers

Type: `property`

The watchers registered with `WATCH()`.

Returns: `Array` The watchers registered with `WATCH()`.

See [WATCH()](../globals/).
