Sunday, December 29, 2013

funcrefs forms

Hello,

Trying to understand the difference (and pros/cons) between the form1
and form2 funcref usage in the following sample code. In a previous
discussion, Nikolay Pavlov said : "[…] I tend to use anonymous functions
(and only them as far as I can)", now I'm wondering why.

Regards,

.vim <--
function! s:SID()
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
endfunction

function! s:objectConstructor(name)
let obj = {}
let obj.name = a:name
let obj.form1 = s:objFuncs.form1
let obj.form2 = function('<SNR>' . s:SID() . '_s:objFuncs_form2')
return obj
endfunction

let s:objFuncs = {}

function! s:objFuncs.form1()
echo self.name
endfunction

function! <SID>s:objFuncs_form2() dict
echo self.name
endfunction

let otst = s:objectConstructor('test')
call otst.form1()
call otst.form2()
-->

--
 ___________________
| $ post_tenebras ↲ |       waouh !
| GNU        \ /    |      /
|          -- * --  |     o
| $ who ↲    / \    |_-- ~_|
| Alexandre Hoïde   |  _/| |
 -------------------

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: