initial commit...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-02 16:00:40 +03:00
commit b1cc554262
5 changed files with 152 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.*
*.vim
*.sw[po]
coverage
node_modules
npm-debug.log

29
LICENSE Normal file
View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2020, Alex A. Naanou
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

63
README.md Normal file
View File

@ -0,0 +1,63 @@
# object-run.js
This module defines a singe method `.run(..)` on `Object.prototype` making
it visible from all JavaScript objects inheriting from Object.
The `.run(..)` method simply executes a function in the context of object
from which `.run(..)` was called.
The return value of `.run(..)` is the non-`undefined` return value of the
passed function.
The use of `.run(..)` enables the concatinative programming style on any
JavaScript structure/object.
## Installation
```shell
$ npm install --save object-run
```
## Basic usage
```javascript
require('object-run')
```
```javascript
var o = {}
.run(function(){
this.x = 123
this.y = 321
})
```
## Components
### `Object.prototype.run(..)`
```
<obj>.run(<func>)
-> <obj>
-> <return-value>
```
```
<func>()
-> undefined
-> <return-value>
```
## License
[BSD 3-Clause License](./LICENSE)
Copyright (c) 2016-2020, Alex A. Naanou,
All rights reserved.
<!-- vim:set ts=4 sw=4 spell : -->

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "object-run",
"version": "1.0.0",
"description": "Implements .run(..) method on object.",
"main": "run.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/flynx/object-run.js.git"
},
"keywords": [
"OOP",
"JavaScript",
"Object"
],
"author": "Alex A. Naanou <alex.nanou@gmail.com>",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/flynx/object-run.js/issues"
},
"homepage": "https://github.com/flynx/object-run.js#readme"
}

30
run.js Normal file
View File

@ -0,0 +1,30 @@
/**********************************************************************
*
* object-run.js
*
* Repo and docs:
* https://github.com/flynx/object-run.js
*
*
***********************************************/ /* c8 ignore next 2 */
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
(function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/
// Run a function in the context of an object...
//
Object.prototype.run
|| Object.defineProperty(Object.prototype, 'run', {
enumerable: false,
value: function(func){
var res = func ?
func.call(this)
: undefined
return res === undefined ?
this
: res }, })
/**********************************************************************
* vim:set ts=4 sw=4 : */ return module })