Prototype


Youngrok Pak at 13 years ago.
  • $(id) = document.getElementById(id)

  • $F(name) name으로 input 필드의 값 가져오기
  • $A(enumerable) enumerable을 Array 객체로 바꿈
  • $H(object) object의 속성을 Hash로 바꿈
  • $R()
    • function demoDollar_R(){
              var range = $R(10, 20, false);
              range.each(function(value, index){
                      alert(value);
              });
      }
  • Try.these() 순서대로 시도해보고 먼저 성공한 결과를 돌려준다.
    • function getXmlNodeValue(xmlNode){
              return Try.these(
                      function() {return xmlNode.text;},
                      function() {return xmlNode.textContent;}
                      );
      }
  • Ajax.Request
    • var myAjax = new Ajax.Request(url, {
              method: 'get', 
              parameters: pars, 
              onComplete: showResponse});
  • Ajax.Updater
    • <script>
              function getHTML()
              {
                      var url = 'http://yourserver/app/getSomeHTML';
                      var pars = 'someParameter=ABC';
                      
      var myAjax = new Ajax.Updater( 'placeholder', url, { method: 'get', parameters: pars });
      
              }
      </script>
      
      <input type=button value=GetHtml onclick="getHTML()">
      <div id="placeholder"></div>
  • Ruby 스타일 Loop
    • for(i=0;i<simpsons.length;i++){
              alert(simpsons[i]);
      }

    ->

    • simpsons.each( function(familyMember){
              alert(familyMember);
      });

  • Array.find
    • var opt = options.find( function(employee){
              return (employee.value == emp_id);
      });


http://www.sergiopereira.com/articles/prototype.js.html


Comments




Wiki at WikiNamu