Elance PrototypeJS Javascript Framework Test Answers

What is the correct syntax for a string of key-value pairs?




Evaluate the following statement: Function class is an extension of a built-in Function object and has no class methods of its own.

Correct for Prototype 1.7.2, incorrect for Prototype 1.6.0
It is an extension of build-in Function object but has at least one class method of its own



To make a contribution of patches or tests to prototypejs.org, you may NOT need:

Rake library
Gnu Linux distributive installed on the machine you are working on
A recent version of Ruby
Code editor



Which of the following is not an example of an AJAX callback?




Select the wrong JavaScript-related MIME-types that handled by Prototype




Which of these is NOT a namespace in PrototypeJS? Event Abstract Number Ajax Enumerable Class Hash

All of these are namespaces in PrototypeJS



If you want to create a hash, which utility would you use?




Do Element.Layout#get and Element#measure work together?

Not currently, but in the next version of Prototype.
Only in the previous version of Prototype.



How can you inherit from a Storage class?

After defining a Descendant using Class.create() method, inherit from class Storage by calling Descendant.inherits() method.
After defining a descendant using Class.create() method, inherit from class Storage by using Object.extend() method.
There is no class-inheritance in the Prototype javascript framework.
var Descendant = new Class(Storage, { newmethod: function() { } });



Which of the following is not a targeted platform for development?

Netscape Navigator
Mozilla Firefox
Apple Safari
Microsoft Internet Explorer



Which namespace is not typically used directly but mixed in to other namespaces?




Instance method String#extractScripts():

Extracts the content of any <script> blocks present in the html page and returns them as a string.
It evaluates the scripts
Returns boolean
Extracts the content of any <script> blocks present in the html page and returns them as an array of strings.



What is the value of t at the end of this code snippet? var t = 1; $R(0,100,true).each(function(){ t++; }); console.log(t);

None of these



How would you wait for the DOM to be loaded so that you can start manipulating the page with Javascript?

document.observe('dom:loaded',function(){ //code here });
document.ready(function(){ //code here });
$(document).ready(function(){ //code here });



Element#measure(property) gives:

pixel value of an element's dimension specified by property
nothing because it does not exist
pixel value of the screen dimension specified by property
value(not only in pixels) of the screen dimension specified by property



In the context of Prototype, “safe” means that AJAX will function how?

On a single browser.
On no browser at all.



What is the alternative of Element.extend() function in Prototype?

The dollar function $()



Internet Explorer doesn't allow the extension of what onto NodeList.prototype?




What object is informed about every AJAX request?




Instance method String#evalJSON():

Evaluates the string as JSON and returns the resulting object
Does not exist, it is a class method
Evaluates the string as JSON and returns an integer
Evaluates the string as JSON and returns a string



Date class is an extension to the built-in Date object and has two instance methods:

Correct. In addition to the given statement it has one class method.
The second statement is incorrect
The first statement is incorrect



By using the Element#on object in Prototype event API, what benefit is being gained?

Obtusely written code and event delegation from within an object.
Concisely written code and event delegation from outside a container.
Negligible written code and object delegation from within a container.
Concisely written code and event delegation from within a container.



How to receive width of an element with id='div1' in pixels?

by using $('div1').clientWidth; or by using $('div1').getStyle('width');
by using $('div1').offsetWidth; or by using $('div1').getStyle('width');
by using $('div1').width; or by using $('div1').getStyle('width');
by using #('div1').offsetWidth; or by using #('div1').getStyle('width');



If you wanted to extend all elements with an additional method to do 'foo' and you have already created the method foo() how would you add it?

$.fn.foo = foo;
$('emelent').foo() = foo
Element.addMethods({'foo' : foo});



The IE properties, offsetWidth and clientHeight along with computed CSS are able to measure elements. Why not use them?

IE properties struggle with “offset” vs. “client” dimensions, and CSS units need to be converted to be compatible.
The version of Prototype has changed so they are incompatible.
They are both outdated.
There is no problem in using them since they are powerful and accurate parameters.



After editing your browser script to work with Prototype extensions, what coding can you add to the end to make it function more solidly?




You have a class that inherits from a parent class. How do you call a parent version of a class method from within a child class method of the same name?

function(){ parent() }
function($super){ $super() }
function($parent){ $parent() }
function(parent){ parent() }



When using data from an untrusted source, it should be sanitized. What does this entail?

Removing all user input.
Removing malicious data from user input.
Blocking users from entering any input.
Increasing malicious data in user input.



The dollar sign method $() returns what?

An DOM element that matches the id passed extended with Prototype methods
An document element that matches the id passed
A list of DOM elements that match the CSS selector passed
Boolean true



What is JSON's meaning and purpose?

JavaScript Oblique Nation, and JSON is a lightweight data-interchange function.
JavaScript Object Notation, and JSON is a lightweight data-interchange format.
JavaScript Order Notion, and JSON is a lightweight data-interchange format.
JavaJava Orbit Notation, and JSON is a lightweight data-conversion format.



What is the result of having the prototype of the native browser objects extended?

It is now possible to add Dom elements.
It is now possible to add Prototype elements.
It is now possible to add Prototype extensions.
All DOM elements have Prototype extensions built-in.



DOM is an acronym for?

Direct Object Management
Document Oriented Model
Document Order Maintenance
Document Object Model



Which code segment has been written using Element#on?

$$('#items li').each( function(item) {
$("messages").on("click", "a.comment_link", function(event, element) {
$("messages").stopObserving("click", this.clickHandler);
$("messages").observe("click", function(event) {



Prototype.K(43560) returns what?




How can you get access to the DOM element using Prototype?

$(id), where id is a string.
$(element) where element is an Element itself.
$(id) or $(element), where id is a string and element is an Element itself.
$$(id) where id is a string.



Element#on has what distinct and beneficial features in Prototype 1.7?

Better support for event deletion and extended element handler removal.
Better support for element delegation and simplified event removal.
Better support for event delegation and simplified event handler removal.
Neglibable support for object delegation and sanctified element handler removal.



What solution has Prototype 1.7 introduced to provide a more concise API?




How to create (define) a class with the name Storage in Prototype Javascript framework?

var Storage = Class.create();
className = function() {}; Storage = new className();
var Storage = Class.extend({ init: function(item){ this.item = item; }, doSomething: function() { } });
var Storage = new Object();



Which callback takes precedence: on<HTTP RESPONSE CODE>, onFailure, or onSuccess?




What object is used to parse JSON?




How would you remove a class named 'removeclass' from an element?

There is not a method to remove class names



What code will return an instance of Element.Layout?

var layout = $('troz').getLayout();
Get.Layout();var layout = $('troz')
var layout.getLayout();



The actual Ajax requests are made by creating instances of

Ajax.apicall object
XmlHttpRequest object
Ajax.Request object
Ajax.Response object



Which four utilities does Prototype use?

$A $w $H $R
$P $w $H $Q
$B $w $Z $R
$S $P $Q $R



If your data is not an instance of an object and you invoke the toJSON method, where should the syntax: toJSON() be located in the string?

At the end.
Nowhere in the string.
In the middle.
At the beginning.



Evaluate the following statement: Hash is a set of key/value pairs with Element.Layout subclass. For convenience a developer can use #H() alias.

More than one statements are incorrect.
One statement is incorrect.
Hash is a set of key/value pairs, has Element.Layout subclass but there is no aliases defined for Hash in Prototype.



If you wanted to make Prototype extensions functional in Internet Explorer, what would you use?




Lets say you have an array with name myArray. How would you organize a loop?

Using "for" statement or Array#each iterator.
Using "for" statement only, Array#each is not an iterator.
Using Array#prototype iterator or "for" statement.
Using "for" statement or Array#iter iterator.



Despite DOM elements having Prototype extensions built-in, will they function in Internet Explorer?

Yes, but this action is not supported by Internet Explorer.
Yes, however Internet Explorer crashes.
Yes, but the configuration file must be edited.



What property stores the active Ajax requests?

There is no property set to the number of active requests



To use JSON with AJAX, what must be invoked on the transport's responseText property?




$w is responsible for?

Splitting an element into a string.
Splitting a string into a larger string.
Converting an array into an object.
Splitting a string into an array.



What is the right syntax of using Element#observe for the click event?

$("element").observe("click", this.clickHandler);
#("element").observe("click", this.clickEventHandler);
#("element").observe("click", this.clickHandler);
$("element").observe("click", this.clickEventHandler);



Why would it be beneficial to use an array in Prototype?

By using an array, Prototype has decreased the number of usable elements.
By using an array, Prototype has extended the number of usable methods.
By using an array, Prototype has decreased the number of usable methods.
By using an array, Prototype has decreased the number of usable objects.



Prototype 1.6 introduced Element.Layout, which can be used for retrieving element measurements

The second statement is incorrect
The first statement is incorrect, right version of introduction is 1.7. Second statement is correct for 1.7
Both statements are incorrect



Method "on()" of Event class can be used to set up event handlers, with or without event delegation. What is not true about Event.on?

Creates an instance of Event.Handler
It works just like Event.observe
It calls Event.Handler#start
Has inner iterator



How can you create an instance of class Storage which has one parameter in constructor?

var inst = new Storage("warehouse"');
Storage.prototype = { initialize: function(name) { this.name = name; }, f: function(message) { return message+", "+this.name; } };
var Storage = Class.create("warehouse");



There is an object in Prototype that is informed about every Ajax request: Ajax.Responders. Is it possible to register callbacks that will fire on a state of ANY Ajax.Request?

Yes, by using "var callback = new Event.Handler(Ajax.Request req)" code snippet
No, to add a group of responders to all Ajax requests you might need to use Abstract.EventObserver class
Yes, by using Ajax.Responders.on
Yes, by using Ajax.Responders.register



Prototype is considered what kind of framework?

A programming framework.
A network framework.
A JavaScript framework for developing dynamic web applications.
An HTML framework.



"data-my-element-info-t".camelize() returns what?

A javascript error



What is the subclass of Ajax.Request, if any?

Ajax.Request is not a class



What object would you use in Prototype, and what are the benefits of using said object?

Ajax.Updater – It significantly reduces the load on your servers by reducing the number of requests.
PeriodicalUpdater – It significantly reduces the load on your servers by increasing the number of requests.
Ajax.PeriodicalUpdater – It significantly increases the load on your servers by reducing the number of requests.
Ajax.PeriodicalUpdater – It significantly reduces the load on your servers by reducing the number of requests.



How would you create a new div element and insert it as the last child of the body?

$$('body').insert(new Element('div'));
$$('body').first().insert(new Element('div'));
$('body').append(new Element('div'));



How can you get a copy of the array without any null or undefined values?

By calling Array#clean() method.
By calling Array#clear() method.
Although Array#compact() method returns a copy of the array without undefined values it keeps null values. There is a trick - write custom function to deal with null values.
By calling Array#compact() method.



DOM methods are mostly encapsulated by what object?




How would you create an AJAX call to get the url '/echomyid'?

new Ajax.Request('/echomyid');



Which class serves a purpose of creation an observer on an element that listens for a particular event, that element's descendants?




The code: var json = transport.responseText.evalJSON(true); will check for what?

Missing user data.
Incorrect user data.
Malicious user data.
Excessive user data.



When writing custom DOM methods, what must be placed as the first argument?

The object itself.
The element itself.
The method itself.
The method and object.



Which method that is not available to convert to JSON in Prototype




Which PrototypeJS method of functions have become a native method of functions?

None of these



What do you use to add your own custom DOM methods?




Class method String#gsub:

Returns the string with the first occurence of a given pattern replaced by either a regular string, the returned value of a function or a Template string
Returns boolean value
Does not exist, it is an instance method
Has second argument "pattern"



Using Element.Layout you can measure elements that are hidden:

always when element has "visibility: hidden"
as long as their parents are visible.
always when style="display: none"



(42).toPaddedString(4) returns what?




The 'onSuccess' callback for any of the Ajax method will auto-convert responses to JSON if what takes place?

Ajax methods will always convert to JSON
Ajax methods require the 'response':'json' option set
The Content Type header is set to application/JSON



When using Element#on as opposed to Element#observe, what is different about its return value?

Element#on has a #stop method which will increase the number of event handlers.
Element#on has a #stop method which will remove Element#observe events.
Element#on has a #stop method which will remove excessive event handlers.
Element#on has a #element method which will remove excessive object handlers.



Here is a snapcode: ' bmw, bugatti & luxury'.scan(/\w+/, alert); How many alert dialongs will you see after executing given snapcode?




Why is event delegation important in Prototype?

It makes it possible to truncate resources to a single container.
It makes it impossible to truncate resources to a single container.
It makes it possible to extend resources to multiple containers.
It makes it impossible to extend resources to a single element.



Is there any utility to split a string into Array?

Yes, it treats all comas as delimiters
No, there is no such utility to serve this purpose
Yes, it treats all whitespaces as delimiters
Yes, it calls "split". Works fine for Prototype 1.6.0



Is it required to use Element#on exclusively?

Yes, though you can downgrade the version and use Element#observe for better performance.
No. Neither of them are recommended.
No. It is recommended that you use Element#observe because it is more efficient.
No. It is perfectly acceptable to continue using Element#observe, though it is less efficient.



-background-color'.camelize(); returns:




After being encapsulated by Element.Methods, what object is it copied over to?

The Method object.
The Element object.
The Object Element
The Order object.



Prototype JS framework with version 1.6.0 defines two additional class properties:

subclasses and superclass
subclass and superclasses
subclass and superclass
subclasses and superclasses



Utilities $A and $R create an array and ObjectRange object. What will be their results given the following string; $A($R('a', 'e')) ?

['a', 'b', 'c', 'd', 'e']
['a', 'e', 'a', 'e', 'e']
['a', 'b', 'a', 'b', 'e']
['a', 'e', 'e', 'e', 'a']



Which class serves the purpose of sophisticated string interpolation?




If you want to create a distribution tarball in the pkg/ directory, what package would you run?

rake package
tar package
rke package
tarball package



What is the shortcut to get a Form element value?




How would you loop over an array of elements (myArray) and set the value of each element to '1'?

myArray.each(function(element){ element.value = '1'; });
$(myArray).each(function(index,element){ $(element).val('1'); });
myArray.loop(function(element){ element.val('1'); });



Is it possible to add a method to class "on-the-fly" in Prototype 1.7, and if so how?

Using Class.extend only.
Using Class.extends.
Using Class#extend, for instance.
Using Class#addMethods.
No it is not possible



What is printed in the console from the below statement console.log("PrototypeJS".blank());

Throws an Javascript Error



How would you select all of the child elements of a specific element that match a CSS selector (.myclass) ?

$('element .myclass')



Select the wrong callback function of Prototype's AJAX object




Lets assume we are calling str.dasherize();. What should be a value of "str" to recieve "one-two-three" string as a result?

{"one", "two", "three"}
"one, two, three"
"one two three"



Evaluate the 4 following premises: 1. RegExp is an extension to the built-in RegExp object 2. Ir has one class method and one instance method 3. instance method is an alias of some native RegExp method 4. instance method returns string value as a result.

One statement is false
All premises are correct
At least two statements are false for Prototype with versions below 1.7
One statement is true, the rest are false



To make a contribution, a developer might need to make a clone of Prototype project from:




Which of the given examples returns "false"?

"{ \"foo\": 0 }".isJSON();
String#isJSON() does not exist
"{ foo: 38 }".isJSON();