# function-stack

> function-stack ==============

Latest version **0.0.2** (published 2015-04-15) · 0 weekly downloads

## Install

```sh
npm install function-stack
pnpm add function-stack
yarn add function-stack
bun add function-stack
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2015-04-15 |
| First published | 2015-04-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | belbis |

## Links

- npm: https://www.npmjs.com/package/function-stack
- npm.io page: https://npm.io/package/function-stack

## Recent versions

- 0.0.2 (latest) — 2015-04-15

## README

function-stack
==============

a simple stack for executing js functions.

on initialization, the stack takes in a list of functions,
appends them to the stack, and executes them.

when a function is pushed into the stack, it is immediately popped off
and executed.

the application use for something like this is a remote script that contains a
library function needed. create a list of function calls, then when the lib is 
loaded, run through them

this was inspired by googletag's [command array](https://developers.google.com/doubleclick-gpt/reference#googletag.CommandArray).


ex:
local script
------------

```javascript
var fns = [];
fns.push(function() {
  notImplemented();
});
```
remote script
-------------

```javascript
function notImplemented() {
  alert('implemented\!')
}

fns = FunctionStack(fns);
```

and example html test:
----------------------
```html
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>A friendly example</title>

  <!-- need to load FunctionStack -->
  <script src="../dist/fs.min.js"></script>
</head>
  <body>
    <script>

      window['_namespace'] = window['_namespace'] || {};

      // first push fn to stack
      window['_namespace'].fns = [];
      window['_namespace'].fns.push(function() {
        window['_namespace'].notImplemented();
      });
    </script>

    <script>
      // now load lib
      setTimeout(function() {

        window['_namespace'] = window['_namespace'] || {};

        window['_namespace'].notImplemented = function() {
          alert('implemented!');
        };
        // then turn array to FunctionStack
        window['_namespace'].fns = FunctionStack(window['_namespace'].fns);
      }, 500);
    </script>
  </body>
</html>
```

license
-----------

the command array samples are released under apache 2.0 license 
so this will as well.


errata
------

an important thing to note is that the functions that are coming
in from the remote script must be available in the global window
usually recommended to set a namespace for the functions so that
they don't interfere

this was designed to be used in an ad serving environment

---
_Source: https://npm.io/package/function-stack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
