Hopefully this (http://mootools.net/shell/gs4QG/) will help to explain
it. :)
On 24/01/2010 7:58 PM, Roman Land wrote:
This is not what I need, I need a way to access the properties of
object who called this function, while when defining the function also
access inside of it two other objects..
var myobj = new Object();
mypbj.val1 = 'useful param';
mypbj.useParam = function(val1/* but not really*/){
//somehow get the val1 inside this function
var _val1 = val1;
this.process(_val1);
} // here I can use .bind / .pass - but they are not work since they
will override the instance variables of the calling object
otherobj = new Object();
otherobj.process = function(val){
console.log(val);
}
otherobj.callback = myobj.useParam;
Can this be done in JS somehow?
Thanks!
Roman
On Sun, Jan 24, 2010 at 12:18 PM, ken <[email protected]
<mailto:[email protected]>> wrote:
(function() {console.log(this)}.bind('Hello world'))(); // this refers
to Hello world
(function() {console.log(this)}.pass('Hello world'))(); // this refers
to window
(function(message) {console.log(message)}.pass('Hello world'))(); //
this refers to window but logs Hello world
On Jan 24, 6:00 pm, Roman Land <[email protected]
<mailto:[email protected]>> wrote:
> Hi,
>
> After reading the code I understand that .pass and .bind are
essentially the
> same, the difference being that with .pass the bind can be null.
> Although the binding is null the original object closure is
still lost in
> the current context, example:http://mootools.net/shell/ck72p/
>
> I dont know if its possible but I am looking for a way to pass
an argument
> at function deceleration time and get it as part of the "this"
or as an
> argument, is there a way to achieve this?
>
> Thanks!
> Roman
>
> --
> ---
> "Make everything as simple as possible, but not simpler."
>
> - Albert Einstein
--
---
"Make everything as simple as possible, but not simpler."
- Albert Einstein