File tree Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -66,10 +66,15 @@ ViewModel.use = function (plugin) {
6666 return utils . warn ( 'Cannot find plugin: ' + plugin )
6767 }
6868 }
69- if ( typeof plugin === 'function' ) {
70- plugin ( ViewModel )
71- } else if ( plugin . install ) {
72- plugin . install ( ViewModel )
69+
70+ // additional parameters
71+ var args = [ ] . slice . call ( arguments , 1 )
72+ args . unshift ( ViewModel )
73+
74+ if ( typeof plugin . install === 'function' ) {
75+ plugin . install . apply ( plugin , args )
76+ } else {
77+ plugin . apply ( null , args )
7378 }
7479}
7580
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ describe('UNIT: API', function () {
6161 assert . ok ( called )
6262 } )
6363
64- it ( 'should install a plugin if its a function itself' , function ( ) {
64+ it ( 'should install a plugin if it’s a function itself' , function ( ) {
6565 var called = false
6666 Vue . use ( function ( vue ) {
6767 called = true
@@ -70,6 +70,36 @@ describe('UNIT: API', function () {
7070 assert . ok ( called )
7171 } )
7272
73+ it ( 'should pass any additional parameter' , function ( ) {
74+ var param1 = 'a' ,
75+ param2 = { b : 'c' }
76+
77+ Vue . use ( function ( vue , p1 , p2 ) {
78+ assert . strictEqual ( p1 , param1 )
79+ assert . strictEqual ( p2 , param2 )
80+ } , param1 , param2 )
81+
82+ Vue . use ( {
83+ install : function ( vue , p1 , p2 ) {
84+ assert . strictEqual ( p1 , param1 )
85+ assert . strictEqual ( p2 , param2 )
86+ }
87+ } , param1 , param2 )
88+ } )
89+
90+ it ( 'should properly set the value of this' , function ( ) {
91+ var plugin = {
92+ install : function ( ) {
93+ assert . strictEqual ( this , plugin )
94+ }
95+ }
96+ Vue . use ( plugin )
97+
98+ Vue . use ( function ( ) {
99+ assert . strictEqual ( this , global )
100+ } )
101+ } )
102+
73103 } )
74104
75105 describe ( 'filter()' , function ( ) {
Original file line number Diff line number Diff line change @@ -42,4 +42,6 @@ Vue.config({silent:true})
4242var testDiv = document . createElement ( 'div' )
4343testDiv . id = 'test'
4444testDiv . style . display = 'none'
45- document . body . appendChild ( testDiv )
45+ document . body . appendChild ( testDiv )
46+
47+ var global = this
You can’t perform that action at this time.
0 commit comments