2016-05-18 0:54 GMT+03:00 mister fish <[email protected]>:
> Hi, I don't have special knowledge of vimscript, but it appears to me that
> this is the expected behavior. I don't believe that the function stores the
> information about the dictionary it lives in; also, if it lives in many
> dictionaries, I would assume it's still just one function reference and not
> copies. In Javascript for example it works exactly this way.
>
Not function. `dict.func` (as well as `dict['func']`) is now a equivalent
of `function(get(dict, 'func'), dict)`: indexing a dictionary creates a
partial. So Andrey expected to store this partial in a dictionary and
retrieve as-is.
To actually do this one needs to use `get(dict, 'func')` now: this
retrieves exactly what is stored in the dictionary. In Python partials are
also not created automatically: `pyeval('vim.bindeval("dict")["func"]')`
will return a copy of original partial, not create the new one with
different binding.
> These also do what I expect:
>
> function! Callback_Test2()
> function! GetColor() dict
> return self.color
> endfunction
> let reddog = { 'color': 'red', 'get_color': function('GetColor') }
> let bluedog = { 'color': 'blue', 'get_color': function('GetColor') }
> echomsg "First dog is " . reddog.get_color()
> " --- prints blue, not red.
> echomsg "Second dog is " . bluedog.get_color()
> endfunction
>
> function! Callback_Test3()
> let reddog = { 'color': 'red' }
> function! reddog.get_color()
> return self.color
> endfunction
> let bluedog = { 'color': 'blue', 'get_color': reddog.get_color }
> echomsg "First dog is " . reddog.get_color()
> " --- and do does this:
> echomsg "Second dog is " . bluedog.get_color()
> endfunction
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub
> <https://github.com/vim/vim/issues/812#issuecomment-219866073>
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.