# this-to-arg

> Convert `this` to the first argument in a function

Latest version **1.0.1** (published 2015-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install this-to-arg
pnpm add this-to-arg
yarn add this-to-arg
bun add this-to-arg
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-10-26 |
| First published | 2015-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Greg Tatum |
| Maintainers | tatumcreative |
| Keywords | this, arguments, functional, parameters, args |

## Links

- npm: https://www.npmjs.com/package/this-to-arg
- Repository: https://github.com/TatumCreative/npm-this-to-arg
- Homepage: https://github.com/TatumCreative/npm-this-to-arg#readme
- Issues: https://github.com/TatumCreative/npm-this-to-arg/issues
- npm.io page: https://npm.io/package/this-to-arg

## Recent versions

- 1.0.1 (latest) — 2015-10-26
- 1.0.0 — 2015-10-26

## README

# this-to-arg

Convert the `this` object in a function to the first parameter for that function. The existing arguments will be shifted right. The reason for this module is for code clarity when writing code using packages and frameworks that assume you want to use the `this` object, or when `this` may need to be used in closures. Sometimes `this` can be a bit too magical in how it gets set. `this-to-arg` makes it more explicit.

# Example

This is a contrived example of using jQuery to create a link that turns into a timer.

## Before

	function startTimer( event ) {
		
		var element = this
		var seconds = 0
		
		setInterval(function() {
			seconds++
			element.innerHTML = seconds
		}, 1000)
		event.preventDefault()
	}
	
	jQuery('a').on('click', startTimer)


## After

	var ThisToArg = require('this-to-arg')
	
	function startTimer( element, event ) {
		
		var seconds = 0
		
		setInterval(function() {
			seconds++
			element.innerHTML = seconds
		}, 1000)
		event.preventDefault()
	}
	
	jQuery('a').on('click', ThisToArg( startTimer ))

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