en.javascript.info/1-js/5-functions-closures/4-closures-usage/3-stringbuffer-with-clear/solution.md
2015-03-10 12:36:58 +03:00

34 lines
480 B
Markdown

```js
//+ run
function makeBuffer() {
var text = '';
function buffer(piece) {
if (arguments.length == 0) { // вызов без аргументов
return text;
}
text += piece;
};
buffer.clear = function() {
text = "";
}
return buffer;
};
var buffer = makeBuffer();
buffer("Тест");
buffer(" тебя не съест ");
alert( buffer() ); // Тест тебя не съест
*!*
buffer.clear();
*/!*
alert( buffer() ); // ""
```