aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorMichael Ennen <mike.ennen@gmail.com>2016-10-28 12:38:36 -0700
committerJames McCoy <jamessan@jamessan.com>2016-12-12 10:17:35 -0500
commitc82dc7a6fd4987fee72320133579b008815b28d1 (patch)
tree26768dfc53a53eb1070d577cedb7459894feeab1 /runtime
parenteb337c9949d679eeb9f0995963c639fdf7772fd4 (diff)
downloadrneovim-c82dc7a6fd4987fee72320133579b008815b28d1.tar.gz
rneovim-c82dc7a6fd4987fee72320133579b008815b28d1.tar.bz2
rneovim-c82dc7a6fd4987fee72320133579b008815b28d1.zip
vim-patch:7.4.1836
Problem: When using a partial on a dictionary it always gets bound to that dictionary. Solution: Make a difference between binding a function to a dictionary explicitly or automatically. https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/eval.txt41
1 files changed, 40 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index f377ebdf31..133f35990c 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,6 +1,5 @@
*eval.txt* For Vim version 7.4. Last change: 2016 Jun 04
-
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -49,6 +48,9 @@ String A NUL terminated string of 8-bit unsigned characters (bytes).
Funcref A reference to a function |Funcref|.
Example: function("strlen")
+ It can be bound to a dictionary and arguments, it then works
+ like a Partial.
+ Example: function("Callback", [arg], myDict)
List An ordered sequence of items |List|.
Example: [1, 2, ['a', 'b']]
@@ -139,6 +141,43 @@ The name of the referenced function can be obtained with |string()|. >
You can use |call()| to invoke a Funcref and use a list variable for the
arguments: >
:let r = call(Fn, mylist)
+<
+ *Partial*
+A Funcref optionally binds a Dictionary and/or arguments. This is also called
+a Partial. This is created by passing the Dictionary and/or arguments to
+function(). When calling the function the Dictionary and/or arguments will be
+passed to the function. Example: >
+
+ let Cb = function('Callback', ['foo'], myDict)
+ call Cb()
+
+This will invoke the function as if using: >
+ call myDict.Callback('foo')
+
+This is very useful when passing a function around, e.g. in the arguments of
+|ch_open()|.
+
+Note that binding a function to a Dictionary also happens when the function is
+a member of the Dictionary: >
+
+ let myDict.myFunction = MyFunction
+ call myDict.myFunction()
+
+Here MyFunction() will get myDict passed as "self". This happens when the
+"myFunction" member is accessed. When making assigning "myFunction" to
+otherDict and calling it, it will be bound to otherDict: >
+
+ let otherDict.myFunction = myDict.myFunction
+ call otherDict.myFunction()
+
+Now "self" will be "otherDict". But when the dictionary was bound explicitly
+this won't happen: >
+
+ let myDict.myFunction = function(MyFunction, myDict)
+ let otherDict.myFunction = myDict.myFunction
+ call otherDict.myFunction()
+
+Here "self" will be "myDict", because it was bound explitly.
1.3 Lists ~