DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • attr
  • / On this page
    • attr

      function
      • source

      scope.attr(key)

      Parameters

      1. key {can-mustache.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.attr(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.attr("name"); //-> "Justin"
      curScope.attr("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.attr("name"); //-> "Brian"
      curScope.attr("surname"); //-> "CanJS"
      curScope.attr("./surname"); //-> undefined
      curScope.attr("../name"); //-> "Justin"
      curScope.attr("../surname"); //-> "CanJS"
      curScope.attr(".././surname"); //-> "undefined"
      curScope.attr("../../name"); //-> "Programmers"
      

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