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

# MAIN

> L'oggetto principale della libreria, con il suo stato e i suoi metodi di basso livello.

`MAIN` è l'oggetto principale della libreria. `M`, `Total` e `jComponent` sono altri nomi dello stesso oggetto. Contiene lo stato della libreria e metodi di basso livello che funzionano con qualsiasi scope. Per il codice di tutti i giorni, usa le [funzioni globali](../globals/) descritte in [Path](../../guides/paths/).

## API

### MAIN.Binder

Type: `class`

La classe delle associazioni dei dati.

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

### MAIN.binders

Type: `property`

Le associazioni dei dati attive.

Returns: `Array` Le associazioni dei dati attive.

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

### MAIN.caller

Type: `property`

L'ultimo plugin chiamato tramite `EXEC()`.

Returns: `Plugin` L'ultimo plugin chiamato tramite `EXEC()`.

Example: Leggi il chiamante
```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`

La stessa funzione di `CL()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | I nomi degli elenchi di codici. |
| `callback` | `Function` | no |  | Una funzione eseguita quando gli elenchi sono stati caricati. |

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

### MAIN.Component

Type: `class`

La classe dei componenti.

Vedi [Componente](../component/).

### MAIN.components

Type: `property`

Le istanze attive dei componenti.

Returns: `Array` Le istanze attive dei componenti.

Vedi [Componente](../component/).

Example: Conta i componenti
```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`

L'archivio dei plugin con un path generato.

Returns: `Object` L'archivio dei plugin con un path generato.

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

### MAIN.def

Type: `property`

Lo stesso oggetto di `DEF`.

Returns: `Object` Lo stesso oggetto di `DEF`.

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

Example: Confronta gli oggetti
```js
console.log(MAIN.def === DEF); // true
```

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

Type: `method`

La stessa funzione di `EMIT()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

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

### MAIN.events

Type: `property`

I gestori degli eventi globali, per nome dell'evento.

Returns: `Object` I gestori degli eventi globali, per nome dell'evento.

Vedi [Eventi](../events/).

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

Type: `method`

Esegue la stessa logica di `EXEC()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | La destinazione della chiamata. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

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

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

Type: `method`

Trova i componenti di un path in uno scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | Lo scope, di solito `window`. |
| `path` | `String` | yes |  | Il path, eventualmente con dei flag. |
| `callback` | `Function` | yes |  | Una funzione che riceve l'array dei componenti. |

I flag nel path restringono il risultato: `@visible`, `@touched`, `@modified`, `@required`, `@invalid`, `@disabled` e `@enabled`.

Example: Trova i componenti
```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`

La stessa funzione di `FLAGS()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `flags` | `String` | yes |  | I flag. |
| `callback` | `Function` | no |  | Una funzione eseguita al termine. |

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

### MAIN.free()

Type: `method`

La stessa funzione di `FREE()`.

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

### MAIN.get(scope, path)

Type: `method`

Legge un valore da qualsiasi oggetto tramite un path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | L'oggetto da cui leggere. |
| `path` | `String` | yes |  | Il path all'interno dell'oggetto. |

Returns: `Object` Il valore.

Example: Leggi un valore annidato
```js
var data = { user: { name: 'Peter' } };
console.log(MAIN.get(data, 'user.name')); // Peter
```

### MAIN.is20

Type: `property`

Identifica la versione principale della libreria.

Returns: `Boolean` Identifica la versione principale della libreria.

Il valore è sempre `true`.

Example: Leggi il valore
```js
console.log(MAIN.is20); // true
```

### MAIN.loaded

Type: `property`

Diventa `true` quando la cache persistente è caricata.

Returns: `Boolean` Diventa `true` quando la cache persistente è caricata.

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

Type: `method`

Crea un'associazione dei dati su un elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | L'elemento. |
| `path` | `String` | yes |  | Il path. |
| `config` | `String` | yes |  | I comandi di associazione. |
| `callback` | `Function` | no |  | Una funzione eseguita quando viene creata l'associazione. |

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

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

Type: `method`

Crea un componente su un elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | L'elemento. |
| `name` | `String` | yes |  | Il nome del componente. |
| `path` | `String` | yes |  | Il path. |
| `config` | `String` | yes |  | La configurazione. |
| `callback` | `Function` | no |  | Una funzione eseguita quando viene creato il componente. |

Example: Crea un componente dal codice
```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`

Importa contenuti in un elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | L'elemento. |
| `path` | `String` | yes |  | L'indirizzo. |
| `config` | `String` | yes |  | La configurazione dell'importazione. |

Funziona come l'elemento [ui-import](../ui-import/).

Example: Importa una parte
```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`

Crea un plugin su un elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery` | yes |  | L'elemento. |
| `path` | `String` | yes |  | Il nome del plugin. |
| `config` | `String` | no |  | La configurazione. |
| `callback` | `Function` | no |  | Una funzione eseguita quando viene creato il plugin. |

Example: Crea un plugin dal codice
```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`

Notifica gli osservatori di un path in uno scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | Lo scope, di solito `window`. |
| `path` | `String` | yes |  | Il path, eventualmente con dei flag. |
| `onlyflags` | `Boolean` | no | `false` | Limita la notifica allo stato dei componenti. |

Con `onlyflags`, i componenti aggiornano solo il proprio stato e gli osservatori non vengono eseguiti.

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

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

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

Type: `method`

La stessa funzione di `OFF()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `callback` | `Function` | no |  | Il gestore da rimuovere. |

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

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

Type: `method`

La stessa funzione di `ON()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `callback` | `Function` | yes |  | Il gestore. |
| `init` | `Boolean` | no | `false` | Chiama anche il gestore una volta. |

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

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

Type: `method`

Converte un valore in un tipo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Il tipo. |
| `value` | `Object` | yes |  | Il valore. |
| `format` | `String` | no |  | Il formato di una data. |

Returns: `Object` Il valore convertito.

I tipi sono `number`, `currency`, `float`, `boolean`, `bool`, `date` e `datetime`. I numeri seguono [DEF.thousandsseparator](../def/) e [DEF.decimalseparator](../def/), mentre le date usano [DEF.dateformat](../def/) quando `format` non è impostato. Un valore che non può essere convertito restituisce `null`. Gli altri tipi restituiscono il valore così com'è.

Example: Converti i valori
```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`

La classe che analizza i path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path, eventualmente con dei flag. |

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

Example: Analizza un 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`

La classe dei plugin.

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

### MAIN.plugins

Type: `property`

Lo stesso oggetto di `PLUGINS`.

Returns: `Object` Lo stesso oggetto di `PLUGINS`.

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

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

Type: `method`

Consegna un valore a una funzione o a un path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | Lo scope di un path. |
| `value` | `Object` | yes |  | Il valore. |
| `target` | `Function|String` | yes |  | Una funzione o un path. |

Una funzione riceve il valore. Un path viene scritto e notificato nello scope.

Example: Consegna un valore a un path
```js
MAIN.process(window, 5, 'stats.total');
console.log(GET('stats.total')); // 5
```

### MAIN.ready

Type: `property`

Diventa `true` quando la libreria è stata avviata.

Returns: `Boolean` Diventa `true` quando la libreria è stata avviata.

Example: Controlla lo stato
```js
ON('ready', function() {
	console.log(MAIN.ready); // true
});
```

### MAIN.resize()

Type: `method`

Misura di nuovo la finestra.

Il metodo aggiorna [WW](../globals/) e [WH](../globals/). Quando le dimensioni sono cambiate, aggiorna la classe del dispositivo sul body ed emette l'[evento](../events/) `resize2`.

### MAIN.root

Type: `property`

L'oggetto `window`, che è lo scope dei path globali.

Returns: `Object` L'oggetto `window`, che è lo scope dei path globali.

Example: Confronta gli oggetti
```js
console.log(MAIN.root === window); // true
```

### MAIN.scrollbars

Type: `property`

Le barre di scorrimento personalizzate attive.

Returns: `Array` Le barre di scorrimento personalizzate attive.

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

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

Type: `method`

Esegue la stessa logica di `SEEX()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | La destinazione. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

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

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

Type: `method`

Scrive un valore in qualsiasi oggetto tramite un path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `scope` | `Object` | yes |  | L'oggetto in cui scrivere. |
| `path` | `String` | yes |  | Il path all'interno dell'oggetto. |
| `value` | `Object` | yes |  | Il valore. |

Gli oggetti mancanti lungo il path vengono creati. Non viene notificato nulla.

Example: Scrivi un valore annidato
```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`

Esegue `SETTER()` per i componenti all'interno di un elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `element` | `jQuery|Plugin` | yes |  | L'elemento o il plugin che limita la ricerca. |
| `name` | `String` | yes |  | Il selettore e il metodo. |
| `a` | `Object` | no |  | Il primo argomento. |
| `b` | `Object` | no |  | Il secondo argomento. |
| `c` | `Object` | no |  | Il terzo argomento. |
| `d` | `Object` | no |  | Il quarto argomento. |

Usa `null` per tutti i componenti. Vedi [SETTER()](../globals/).

Example: Limita una chiamata a un elemento
```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`

L'ambiente rilevato: `os`, `browser` e `device`.

Returns: `Object` L'ambiente rilevato: `os`, `browser` e `device`.

`device` può essere `desktop`, `tablet`, `mobile` o `tv`. Il valore è disponibile a partire dall'evento `ready`.

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

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

Type: `method`

La stessa funzione di `UNWATCH()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path. |
| `callback` | `Function` | no |  | L'osservatore da rimuovere. |

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

### MAIN.version

Type: `property`

La versione della libreria.

Returns: `Number` La versione della libreria.

Example: Leggi la versione
```js
console.log(MAIN.version); // 20.015
```

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

Type: `method`

La stessa funzione di `WATCH()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path. |
| `callback` | `Function` | yes |  | L'osservatore. |
| `init` | `Boolean` | no | `false` | Chiama anche l'osservatore una volta. |

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

### MAIN.watchers

Type: `property`

Gli osservatori registrati con `WATCH()`.

Returns: `Array` Gli osservatori registrati con `WATCH()`.

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