Просмотр исходного кода

scope should not overwrite vm properties

Evan You 12 лет назад
Родитель
Сommit
810c584400
2 измененных файлов с 5 добавлено и 3 удалено
  1. 2 2
      src/compiler.js
  2. 3 1
      src/utils.js

+ 2 - 2
src/compiler.js

@@ -27,7 +27,7 @@ function Compiler (vm, options) {
 
     // extend options
     options = compiler.options = options || {}
-    utils.extend(compiler, options.compilerOptions || {})
+    utils.extend(compiler, options.compilerOptions)
 
     // initialize element
     compiler.setupElement(options)
@@ -35,7 +35,7 @@ function Compiler (vm, options) {
 
     // copy scope properties to vm
     var scope = options.scope
-    if (scope) utils.extend(vm, scope)
+    if (scope) utils.extend(vm, scope, true)
 
     compiler.vm  = vm
     vm.$compiler = compiler

+ 3 - 1
src/utils.js

@@ -47,8 +47,10 @@ module.exports = {
     /*
      *  simple extend
      */
-    extend: function (obj, ext) {
+    extend: function (obj, ext, protective) {
+        if (!ext) return
         for (var key in ext) {
+            if (protective && obj[key]) continue
             obj[key] = ext[key]
         }
     },