# "this" explicit binding using "bind" function example from YDKJS

**URL:** <https://forum.freecodecamp.org/t/this-explicit-binding-using-bind-function-example-from-ydkjs/131705>\
**Category:** General\
**Tags:** this, explicit, bind, ydkjs\
**Created:** [June 25, 2017, 6:15pm UTC](https://forum.freecodecamp.org/t/this-explicit-binding-using-bind-function-example-from-ydkjs/131705 "2017-06-25T18:15:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RickSanch3z](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ricksanch3z/32/25931_2.png) [@RickSanch3z](https://forum.freecodecamp.org/u/RickSanch3z)\
**Post date:** [June 25, 2017, 6:15pm UTC](https://forum.freecodecamp.org/t/this-explicit-binding-using-bind-function-example-from-ydkjs/131705/1 "2017-06-25T18:15:02Z")

</div>

Hello,  
I have a question about how “this” explicit binding and how works in general the next example of code:

```
function foo(something) {
	console.log( this.a, something );
	return this.a + something;
}

// simple `bind` helper
function bind(fn, obj) {
	return function() {
		return fn.apply( obj, arguments );
	};
}

var obj = {
	a: 2
};

var bar = bind( foo, obj );

var b = bar( 3 ); // 2 3
console.log( b ); // 5

```

When we return `bind(foo, obj)` our `bar` object should equal `function() { return fn.apply(obj, arguments); }`. But on the next line we pass an argument 3 to bar, `bar(3)`. But how I understand bar is an object function that do not take any argument? Or how it’s work exactly?

Thank you.

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [June 25, 2017, 6:35pm UTC](https://forum.freecodecamp.org/t/this-explicit-binding-using-bind-function-example-from-ydkjs/131705/2 "2017-06-25T18:35:49Z")

</div>

Unlike many other languages, you can pass as many arguments to a JavaScript function as you want. If you pass more arguments than you have named parameters, the remainder will mostly be ignored. All arguments reside in the `arguments` object, which is an array-like. This can be passed directly to `function.prototype.apply`, as you see in the example, because `apply` takes an array (or array-like) of arguments for the function being called.

```auto
function foo() {
    console.log(arguments);
}
//call without arguments
foo(); //Arguments []

//call with random arguments
foo(1,2,3,4,5,"dog", {name:"woobang"}); //Arguments [1, 2, 3, 4, 5, "dog", {name: "woobang"}]

```

---

<div class="post-metadata">

**Author:** ![RickSanch3z](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ricksanch3z/32/25931_2.png) [@RickSanch3z](https://forum.freecodecamp.org/u/RickSanch3z)\
**Post date:** [June 25, 2017, 8:14pm UTC](https://forum.freecodecamp.org/t/this-explicit-binding-using-bind-function-example-from-ydkjs/131705/3 "2017-06-25T20:14:52Z")

</div>

Thanks for information. I read about “arguments” object and how we can use apply to pass an array of arguments and how I understood we can use “arguments” to list them and use as we need.  
For sure I’ll try to declare explicitly function parameters. At least for me it’s more convenient.  
P.S.: Interesting to check if strict-mode insist to explicit declaration of function parameters.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:55pm UTC](https://forum.freecodecamp.org/t/this-explicit-binding-using-bind-function-example-from-ydkjs/131705/4 "2021-01-17T20:55:16Z")

</div>

Closed on January 17, 2021, 8:55pm UTC


