DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
    • can-control
    • can-event
    • can-event/async/async
    • can-event/batch/batch
    • can-observation
    • can-simple-map
    • can-util
    • can-view-callbacks
    • can-view-live
    • can-view-model
    • can-view-nodelist
    • can-view-parser
    • can-view-scope
      • types
        • Meta
      • static
        • Options
      • prototype
        • add
        • compute
        • get
        • peek
        • set
    • can-view-target
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Infrastructure
  • /
  • can-view-scope
  • /
  • get
  • / On this page
    • get

      function
      • source

      scope.get(key [, options])

      Walks up the scope to find a value at key. Stops at the first context where key has a value.

      scope.get("first.name");
      

      Parameters

      1. key {key}:

        A dot seperated path. Use "." if you have a property name that includes a dot.

      Returns

      {*}:

      The found value or undefined if no value is found.

      Use

      scope.get(key) looks up a value in the current scope's context, if a value is not found, parent scope's context will be explored.

      var list = [{name: "Justin"},{name: "Brian"}],
          justin = list[0];
      
      var curScope = new Scope(list).add(justin);
      
      curScope.get("name"); //-> "Justin"
      curScope.get("length"); //-> 2
      

      Prefixing a key with "./" prevents any parent scope look ups. Prefixing a key with one or more "../" shifts the lookup path that many levels up.

      var list = [{name: "Justin"},{name: "Brian"}];
      list.name = "Programmers";
      list.surname = "CanJS";
      
      var justin = list[0];
      var brian = list[1];
      var curScope = new Scope(list).add(justin).add(brian);
      
      curScope.get("name"); //-> "Brian"
      curScope.get("surname"); //-> "CanJS"
      curScope.get("./surname"); //-> undefined
      curScope.get("../name"); //-> "Justin"
      curScope.get("../surname"); //-> "CanJS"
      curScope.get(".././surname"); //-> "undefined"
      curScope.get("../../name"); //-> "Programmers"
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.