Magento Front End Developer - Test Questions

Customize and Create Javascript

6. Customize and Create JavaScript Within the Magento Framework (8%)

Key Areas of Study

  • Know how to perform standard Javascript/Prototype functions - not just those uses within the frontend of Magento
  • Understand how to use prototype to extend core JS classes within Magento (in an upgrade safe manner)

Questions

6.1 Using prototype.js, which selector would be used to target a group of paragraphs with the class of green?
A. $$('p.green')
B. $('div').children('p.green')
C. $('.green')
D. $$('p > .green')
6.2 Given that the prototype library is included - what would be the result of the following code?
<script type="text/javascript">
    Person = Class.create();

    Person.prototype = {
         initialize: function(name)
         {
              this.name = name;
              this.sayHello('Hello');
         },

         sayHello: function (message)
         {
              return(this.name+' says '+message);
         }
    };

    Person.prototype.sayHello = Person.prototype.sayHello.wrap( function (parentMethod, message, flag) {
         if (flag){
            return(message+' Shouted '+this.name);
        } else {
            return parentMethod(message);
        }
     });

    var Jimmy = new Person('Jimmy');

    alert(Jimmy.sayHello('Hi!', true));
    alert(Jimmy.sayHello('Hi!', false));
</script>

A. "Undefined" followed by "[Object]"
B. "Jimmy says Hi!" followed by "Hi! Shouted Jimmy"
C. "Hi! Shouted Jimmy" followed by "Jimmy says Hi!"
D. "Undefined" followed by "Jimmy says Hi!"