# Call() and apply() methods

**URL:** <https://forum.kirupa.com/t/call-and-apply-methods/265895>\
**Category:** Uncategorized\
**Created:** [July 14, 2008, 11:35am UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895 "2008-07-14T11:35:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volgogradetz](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volgogradetz](https://forum.kirupa.com/u/Volgogradetz)\
**Post date:** [July 14, 2008, 11:35am UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895/1 "2008-07-14T11:35:05Z")

</div>

Hello, Kirupa community! This is my first post here.  
I’m interesting in following methods:

```auto
 
Function.apply ();
Function.call ();

```

I’ve never used it before and confused a little when saw examples in help.  
I tried to copy Function.call () example in my custom class, but errors occurs. I tried to search on forum and site but with no result. Is any tutorial exists to understand their purpose.

---

<div class="post-metadata">

**Author:** ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)\
**Post date:** [July 14, 2008, 11:50am UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895/2 "2008-07-14T11:50:57Z")

</div>

You don’t _have_ to use these functions you know. They’re there for specific needs you may have, you’re not supposed to use them randomly without knowing what they do and watch what happens.

Anyway, a good place to start would be to check the AS Dictionary on [Function.apply and [URL=“http://www.adobe.com/support/flash/action\_scripts/actionscript\_dictionary/actionscript\_dictionary370.html”]Function.call](http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary369.html). They should give you a good idea of what these functions do.

---

<div class="post-metadata">

**Author:** ![Volgogradetz](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volgogradetz](https://forum.kirupa.com/u/Volgogradetz)\
**Post date:** [July 14, 2008, 12:24pm UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895/3 "2008-07-14T12:24:15Z")

</div>

Yeah, I know about language reference, but it not friendly sometimes. I never used this methods so I thought it could be useful and I tried to understand them. That what I found (maybe it’ll help somebody):

```auto
class Test_1{
	private var c:Number = 100;
	public function seeObj ():Void{
		trace (c);
	}
}

```

```auto
class Test_2{
	private var c:Number = 200;
}

```

```auto
class Main{
	public static function main():Void{
		var a:Test_1 = new Test_1 ();
		a.seeObj ();//output: 100
		
		var b:Test_2 = new Test_2 ();
		a.seeObj.call(b);//output 200
	}
}

```

So it works like Delegate, but between instanses…

---

<div class="post-metadata">

**Author:** ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)\
**Post date:** [July 14, 2008, 1:15pm UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895/4 "2008-07-14T13:15:48Z")

</div>

Sort of, yes. They simply take the function and apply it as a method of the thisObject passed as the first parameter, and using the parameters further specified in the second parameter (and onward in the case of Function.call). Your example illustrates perfectly how it can be used.

---

<div class="post-metadata">

**Author:** ![Volgogradetz](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volgogradetz](https://forum.kirupa.com/u/Volgogradetz)\
**Post date:** [July 14, 2008, 1:20pm UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895/5 "2008-07-14T13:20:24Z")

</div>

Thanks for helping me!

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [July 14, 2008, 9:22pm UTC](https://forum.kirupa.com/t/call-and-apply-methods/265895/6 "2008-07-14T21:22:29Z")

</div>

> I never used this methods so I thought it could be useful and I tried to understand them.

That’s a pretty good attitude to have, I think.

> So it works like Delegate, but between instanses…

The Delegate class uses `apply`:

```auto
static function create(obj:Object, func:Function):Function
	{
		var f = function()
		{
			var target = arguments.callee.target;
			var func = arguments.callee.func;

			return func.apply(target, arguments);
		};

		f.target = obj;
		f.func = func;

		return f;
	}

```
