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
  • / On this page
    • can-view-scope

      module

      Create a lookup node for [can-mustache.key keys].

      • npm package badge
      • Star
      • source

      new Scope(context, [parent], [meta] )

      Parameters

      1. context {*}:

        A value that represents the current context. This is often an object or observable and is the first place a key is looked up.

      2. parent {can-view-scope}:

        The parent scope. If a key value is not found in the current scope, it will then look in the parent scope.

      3. meta {Meta}:

        A configuration object that can specify special behavior of the context.

      Returns

      {can-view-scope}:

      Returns a scope instance.

      Use

      A can-view-scope represents a lookup context and parent contexts that can be used to lookup a key value.

      If no parent scope is provided, only the scope's context will be explored for values. For example:

      var data = {name: {first: "Justin"}},
          scope = new Scope(data);
      
      scope.get("name.first") //-> "Justin"
      scope.get("length")     //-> undefined
      

      However, if a parent scope is provided, key values will be searched in the parent's context after the initial context is explored. For example:

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

      Use add to easily create a new scope from a parent scope like:

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

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