# Call code with commands and EXEC

> Register commands with component.command() and call them with CMD(), or call a plugin method with EXEC('plugin/method').

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 39dc5c5a78e25e6e23174948c2caa281a46d2d0b99027a9540e82ac791c548fa
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

Two ways to trigger code without a direct reference to the object that owns it:

- A component registers a **command** with `self.command(name, fn)`, and the code that holds the component instance runs it with `instance.CMD(name, a, b, c)` (`element[0].$uicomponent` is the instance of a `<ui-component>`). Use it for actions such as "open this window" or "refresh that list". The global `CMD(name)` is declared to reach every component, but in jComponent 20.014 it cuts a name that has no space, so it does nothing: use the instance, or `EXEC()`.
- `EXEC('plugin/method', a, b)` calls the method `method` of the plugin that lives on the path `plugin`; a plain function name (`EXEC('myfunction')`) calls a global function. The `exec` command of `ui-bind` and the `exec` option of many components take the same names.

```html public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<ui-plugin path="cart">
		<p>Items: <ui-bind path="?.count" config="text:value"></ui-bind></p>
	</ui-plugin>
	<ui-component name="notice" id="notice"></ui-component>

	<script>

		PLUGIN('cart', function(self) {
			self.add = function(n) {
				self.set('count', (self.get('count') || 0) + n);
			};
			self.make = function() {
				self.set('count', 0);
			};
		});

		COMPONENT('notice', function(self) {
			self.make = function() {
				self.html('<i class="text"></i>');
				self.command('say', function(text) {
					self.find('.text').text(text);
				});
			};
		});

		function logout(arg) {
			window.loggedout = arg;
		}

	</script>

</body>
</html>
```
