# Estender componentes e plugins com EXTENSION

> Acrescente comportamento a um componente existente a partir de fora, sem editar o seu código-fonte, com EXTENSION().

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: pt
Content-SHA256: 815a4e359db73b625f8b95c9fa7fd752fd3940cf28161d1d76da2f00c9f3cd95
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

`EXTENSION(name, config, callback)` acrescenta código a cada instância do componente `name` (ou do plugin `@name`) quando é criada. O callback recebe a instância e a sua config, exatamente como uma declaração, pelo que pode acrescentar métodos, alterar opções ou escutar eventos. É assim que uma aplicação personaliza componentes de terceiros sem os bifurcar.

```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-component name="label" config="text:Hello"></ui-component>

	<script>

		COMPONENT('label', 'text:', function(self, config) {
			self.make = function() {
				self.html('<span></span>');
				self.find('span').text(config.text);
			};
		});

		EXTENSION('label', 'suffix:!', function(self, config) {
			self.shout = function() {
				self.find('span').text(config.text.toUpperCase() + config.suffix);
			};
			self.extended = true;
		});

	</script>

</body>
</html>
```
