This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Can You Give An Example Of How To Build A Collection? |
|
Answer» VAR Song = Backbone.Model.extend({ var Song = Backbone.Model.extend({ |
|
| 2. |
What Is Collection In Backbone.js? |
|
Answer» Backbone collections are simply an ordered set of models. Typically, your collection will only USE ONE type of model but models themselves are not limited to a type of collection. VAR Song = Backbone.Model.extend({ Backbone collections are simply an ordered set of models. Typically, your collection will only use one type of model but models themselves are not limited to a type of collection. var Song = Backbone.Model.extend({ |
|
| 3. |
What Are “:params” And “*splats” In Dynamic Routing? |
|
Answer» Backbone uses two styles of variables when implementing routes:
Backbone uses two styles of variables when implementing routes: |
|
| 4. |
What Is Dynamic Routing? |
|
Answer» In case of Dynamic ROUTING, you can use variables in the route. For example, you might want to retrieve a post with a VARIABLE id with a friendly URL string. You can specify variable name in the route as :variablename in dynamic routing. <script> In case of Dynamic Routing, you can use variables in the route. For example, you might want to retrieve a post with a variable id with a friendly URL string. You can specify variable name in the route as :variablename in dynamic routing. <script> |
|
| 5. |
What Is Router In Backbone.js? |
|
Answer» Backbone routers are used for routing your applications URLs when using hash tags(#). In the traditional MVC sense, they don’t necessarily fit the semantics and if you have read “What is a view?” it will elaborate on this point. Though a Backbone “router” is still very useful for any application/feature that needs URL routing/HISTORY capabilities. Defined routers should always contain at least one route and a function to map the particular route to. Routes interpret anything after “#” tag in the URL. All links in your application should target “#/action” or “#action”. (APPENDING a forward slash after the HASHTAG looks a bit nicer, e.g. HTTP://wisdomjobs.com/#/user/help). <script> Backbone routers are used for routing your applications URLs when using hash tags(#). In the traditional MVC sense, they don’t necessarily fit the semantics and if you have read “What is a view?” it will elaborate on this point. Though a Backbone “router” is still very useful for any application/feature that needs URL routing/history capabilities. Defined routers should always contain at least one route and a function to map the particular route to. Routes interpret anything after “#” tag in the URL. All links in your application should target “#/action” or “#action”. (Appending a forward slash after the hashtag looks a bit nicer, e.g. http://wisdomjobs.com/#/user/help). <script> |
|
| 6. |
How Can You Use Template Variables? |
|
Answer» You can access template variables with <%= %>. <script type="text/template" id="search_template"> You can access template variables with <%= %>. <script type="text/template" id="search_template"> |
|
| 7. |
How Can You Attach Listeners To Events In A View? |
|
Answer» USE the “events” attribute of Backbone.View. Remember that event listeners can only be attached to CHILD elements of the “el” PROPERTY. See example below: SearchView = Backbone.View.extend({ Use the “events” attribute of Backbone.View. Remember that event listeners can only be attached to child elements of the “el” property. See example below: SearchView = Backbone.View.extend({ |
|
| 8. |
How Can You Use Underscore Templates In Backbone.js Views? |
Answer»
See the below example: <SCRIPT type="TEXT/template" id="search_template"> See the below example: <script type="text/template" id="search_template"> |
|
| 9. |
What Is “el” Property Of Backbone.js View? |
|
Answer» The “EL” PROPERTY references the DOM OBJECT created in the browser. Every Backbone.js VIEW has an “el” property, and if it is not defined, Backbone.js will construct its own, which is an EMPTY div element. The “el” property references the DOM object created in the browser. Every Backbone.js view has an “el” property, and if it is not defined, Backbone.js will construct its own, which is an empty div element. |
|
| 10. |
How Do You Define View In Backbone.js? |
|
Answer» You can define views in Backbone.js similar to Backbone models. SEE example below: SearchView = Backbone.VIEW.extend({ You can define views in Backbone.js similar to Backbone models. See example below: SearchView = Backbone.View.extend({ |
|
| 11. |
What Is View In Backbone.js? |
| Answer» | |
| 12. |
What Are The Tips/tricks/practice, With Respect To Model, You Follow? |
|
Answer» Below are some practices you should follow while working with Backbone models: Get all the Current ATTRIBUTES obj.attributes gives a direct reference to the attributes and you should be careful when playing with it. Best practice would SUGGEST that you use .set() to edit attributes of a model to take advantage of backbone listeners. var person = new Person({ NAME: "Thomas", age: 67}); var attributes = person.toJSON(); // { name: "Thomas", age: 67} /* This simply returns a copy of the current attributes. */ var attributes = person.attributes; Validate Data Before You Set or Save It Always implement validate() method so that Backbone validates the input before setting any attribute value. It ensures that invalid data is not stored on your server. Person = Backbone.Model.extend({ Below are some practices you should follow while working with Backbone models: Get all the Current Attributes obj.attributes gives a direct reference to the attributes and you should be careful when playing with it. Best practice would suggest that you use .set() to edit attributes of a model to take advantage of backbone listeners. var person = new Person({ name: "Thomas", age: 67}); var attributes = person.toJSON(); // { name: "Thomas", age: 67} /* This simply returns a copy of the current attributes. */ var attributes = person.attributes; Validate Data Before You Set or Save It Always implement validate() method so that Backbone validates the input before setting any attribute value. It ensures that invalid data is not stored on your server. Person = Backbone.Model.extend({ |
|
| 13. |
How Backbone Decides If It Should Use Post/get/ Request To The Server? What Are The Methods Backbone Has Reserved For These Operations? |
|
Answer» If we instantiate a model with an id, Backbone.js will automatically perform a GET request to the urlRoot + ‘/id’ using fetch() method. (CONFORMING to RESTful conventions) If the id attribute of the model is null, Backbone.js will send a POST request to the urlRoot of the server using save() method. If the id attribute of the model is not null, Backbone.js will send a PUT request instead of a POST request using save() method. If a model has an id we know that it exists on the server, so if we wish to remove it from the server we can call DESTROY() method. destroy will fire off a DELETE /user/id (conforming to RESTful conventions). See the example below for all these above operations: // Here we have set only the `id` of the model so it will call fetch() method. If we instantiate a model with an id, Backbone.js will automatically perform a GET request to the urlRoot + ‘/id’ using fetch() method. (conforming to RESTful conventions) If the id attribute of the model is null, Backbone.js will send a POST request to the urlRoot of the server using save() method. If the id attribute of the model is not null, Backbone.js will send a PUT request instead of a POST request using save() method. If a model has an id we know that it exists on the server, so if we wish to remove it from the server we can call destroy() method. destroy will fire off a DELETE /user/id (conforming to RESTful conventions). See the example below for all these above operations: // Here we have set only the `id` of the model so it will call fetch() method. |
|
| 14. |
How The Actions Performed On Model Is Translated To Restful Operations? Give An Example.? |
|
Answer» Models are used to represent data from your server and actions you perform on them will be translated to RESTful operations. The ID attribute of a model identifies how to find it on the database usually mapping to the surrogate key. Suppose you have a table Users with columns id, name, email and you want to save the model BACK on server when user clicks save button. If the id attribute of the model is NULL, Backbone.js will send a POST request to the urlRoot of the server. For this, see the example below: var UserModel = Backbone.Model.extend({ Models are used to represent data from your server and actions you perform on them will be translated to RESTful operations. The id attribute of a model identifies how to find it on the database usually mapping to the surrogate key. Suppose you have a table Users with columns id, name, email and you want to save the model back on server when user clicks save button. If the id attribute of the model is null, Backbone.js will send a POST request to the urlRoot of the server. For this, see the example below: var UserModel = Backbone.Model.extend({ |
|
| 15. |
How Can You Track Any Change In Model Attribute Value? |
|
Answer» All attributes of a model can have listeners bound to them to detect changes to their values. In our initialize function, we are going to bind a function call EVERYTIME we change the value of our attribute. In this case, if the name of our “person” changes, we will alert their NEW name. Syntax for attaching callback to change EVENT of attribute is this.on(“change”, function(model){});. See the EXAMPLE below: Person = Backbone.Model.extend({ All attributes of a model can have listeners bound to them to detect changes to their values. In our initialize function, we are going to bind a function call everytime we change the value of our attribute. In this case, if the name of our “person” changes, we will alert their new name. Syntax for attaching callback to change event of attribute is this.on(“change”, function(model){});. See the example below: Person = Backbone.Model.extend({ |
|
| 16. |
How Can You Write The Business Logic In Model? |
|
Answer» We can write the methods which contain the business logic. Person = Backbone.Model.extend({ We can write the methods which contain the business logic. See the example below: Person = Backbone.Model.extend({ |
|
| 17. |
Can You Have Default Values For Model? If Yes, How? |
|
Answer» Yes, we can set default VALUES for the MODEL ATTRIBUTES. See the example below: MyClass = Backbone.Model.extend({ Yes, we can set default values for the model attributes. See the example below: MyClass = Backbone.Model.extend({ |
|
| 18. |
How Can You Get The Attribute Value Of A Model? |
|
Answer» You can get the value of model attribute by USING .get() METHOD. See the example below: //Set attributes You can get the value of model attribute by using .get() method. See the example below: //Set attributes |
|
| 19. |
How Can You Set Attributes Of A Model? |
|
Answer» You can set attributes of a model in two ways. USING constructor parameter or .set(). See the below EXAMPLE: var myObj = new MYCLASS({ attrib1: "Thomas", attrib2: 67}); You can set attributes of a model in two ways. Using constructor parameter or .set(). See the below example: var myObj = new MyClass({ attrib1: "Thomas", attrib2: 67}); |
|
| 20. |
What Is Models In Backbone.js? |
|
Answer» Models are used to represent data from your server. Model in BackboneJs contains:
MYCLASS = Backbone.Model.extend({ Models are used to represent data from your server. Model in BackboneJs contains: MyClass = Backbone.Model.extend({ |
|
| 21. |
What Is Backbone.js? How Does It Help Developers? |
|
Answer» BackboneJs is a JavaScript framework which ALLOWS the developers to make their life easier by providing the below features: Model:– Store data Model can have listeners BOUND to them to detect CHANGES to their VALUES Collection: Group of models View: Represents UI Routing: Manages how to show appropriate view when request through URL BackboneJs is a JavaScript framework which allows the developers to make their life easier by providing the below features: Model:– Store data Model can have listeners bound to them to detect changes to their values Collection: Group of models View: Represents UI Routing: Manages how to show appropriate view when request through URL |
|
| 22. |
Explain What Is Model.cid? |
|
Answer» MODEL.cid WORKS as a unique IDENTIFIER. It is a special property of models, the cid or client id is AUTOMATICALLY assigned to all models when they are first created. This property is useful when the model is not saved to the server, but needs to be visible in the UI. It TAKES the from c1,c2…. Model.cid works as a unique identifier. It is a special property of models, the cid or client id is automatically assigned to all models when they are first created. This property is useful when the model is not saved to the server, but needs to be visible in the UI. It takes the from c1,c2…. |
|
| 23. |
In Backbone View, What Is The Use Of Setelement? |
|
Answer» setElement function is USED when Backbone VIEW has to be APPLIED to a different DOM ELEMENT. setElement function is used when Backbone view has to be applied to a different DOM element. |
|
| 24. |
What Is Backbone.sync Is Used For? |
|
Answer» When BACKBONE wants to SAVE or read a model to the SERVER it calls out a FUNCTION called as Backbone.sync. When Backbone wants to save or read a model to the server it calls out a function called as Backbone.sync. |
|
| 25. |
Explain What Is The Function Of Parse? |
|
Answer» When ever a MODEL’s DATA is returned by the SERVER, in fetch and save , this data is called parse. It is called by Backbone WHENEVER a COLLECTION’s models are returned by server, in fetch. When ever a model’s data is returned by the server, in fetch and save , this data is called parse. It is called by Backbone whenever a collection’s models are returned by server, in fetch. |
|
| 26. |
What Is The Function Of Escape? |
|
Answer» It gets the current VALUE of an attribute from the model but returns the HTML-escaped VERSION of a model’s attribute. It is helpful in PREVENTING XSS attacks, if you are INTERPOLATING data from the model into HTML. It gets the current value of an attribute from the model but returns the HTML-escaped version of a model’s attribute. It is helpful in preventing XSS attacks, if you are interpolating data from the model into HTML. |
|
| 27. |
Mention What Are The Typical Problems You Might Face With The Backbone View Code? |
| Answer» | |
| 28. |
What Are The Configuration Options Available? |
|
Answer» The CONFIGURATION OPTIONS AVAILABLE are: The configuration options available are: |
|
| 29. |
Explain When You Can Use Unbinding Function In Backbone.js? |
|
Answer» When you WANT to REMOVE the VALIDATION BINDING on the model or all models , removing all EVENTS hooked up on the collection, you can use Unbinding function. For example : Backbone.Validation.Unbind(view) [ This will remove the validation binding] When you want to remove the validation binding on the model or all models , removing all events hooked up on the collection, you can use Unbinding function. For example : Backbone.Validation.Unbind(view) [ This will remove the validation binding] |
|
| 30. |
What Is The Function Of Tojson? |
|
Answer» It returns a shallow copy of the model’s attribute for JSON stringification. This function is used for persistence, SERIALIZATION and for AUGMENTATION before being sent to the SERVER. This does not RETURN a JSON string. It returns a shallow copy of the model’s attribute for JSON stringification. This function is used for persistence, serialization and for augmentation before being sent to the server. This does not return a JSON string. |
|
| 31. |
What Is Model.attributes? |
|
Answer» The attributes property is the internal hash containing the model’s state, USUALLY a form of the JSON object representing the model data on the server. It is OFTEN a STRAIGHTFORWARD SERIALIZATION of a row from the database. The attributes property is the internal hash containing the model’s state, usually a form of the JSON object representing the model data on the server. It is often a straightforward serialization of a row from the database. |
|
| 32. |
Explain What Is Converter In Backbone.js? |
|
Answer» A function is called when model’s attribute is COPIED to an html ELEMENT or when an html element VALUE is copied into a model’s attribute, this function is REFERRED as Converter in Backbone.js A function is called when model’s attribute is copied to an html element or when an html element value is copied into a model’s attribute, this function is referred as Converter in Backbone.js |
|
| 33. |
What Is The Most Powerful Capabilities Of The Modelbinder ? |
|
Answer» The most POWERFUL capabilities of ModelBinder CLASS is that it enables you to define scope when you create your bindings using JQUERY.
The most powerful capabilities of ModelBinder class is that it enables you to define scope when you create your bindings using jQuery. |
|
| 34. |
Explain What Is Modelbinder In Backbone.js ? |
|
Answer» To MAKE synchronization process of views and MODELS TOGETHER, MODELBINDER CLASS is used. To make synchronization process of views and models together, ModelBinder class is used. |
|
| 35. |
Explain How You Can Use Backbone.js For Multiple Page Web App? |
|
Answer» For multiple page web app in backbone.JS there are lots of consideration but here are two which can be useful. Serving the page : In this, where you want to have your web server ROUTE everything to the server route everything to SERVE the same static page. That means that everything in http://wisdomjobs.com/* will serve /var/www/wisdomjobs.com/index.html. once the static page is LOADED, the JS on that page will decide what to do given the url Push State : You can still use backbone routing to do your routing, but don’t use hashbangs. This will allow you to navigate to URLS without actually needing a page refresh. For multiple page web app in backbone.js there are lots of consideration but here are two which can be useful. Serving the page : In this, where you want to have your web server route everything to the server route everything to serve the same static page. That means that everything in http://wisdomjobs.com/* will serve /var/www/wisdomjobs.com/index.html. once the static page is loaded, the JS on that page will decide what to do given the url Push State : You can still use backbone routing to do your routing, but don’t use hashbangs. This will allow you to navigate to URLs without actually needing a page refresh. |
|
| 36. |
Explain What Is Backbone.js Models? |
|
Answer» Backbone.js MODELS are OBJECT and core of backbone.js. It contains an array of ATTRIBUTES and listens for events. To represent your data, Backbone provides a model object. For EXAMPLE, you have a to do list, you would have a model representing each ITEM on that list. Backbone.js models are object and core of backbone.js. It contains an array of attributes and listens for events. To represent your data, Backbone provides a model object. For example, you have a to do list, you would have a model representing each item on that list. |
|
| 37. |
Explain What Is View In Backbone.js? |
|
Answer» Backbone view is a Javascript object that manages a specific DOM ELEMENT and descendants.
Backbone view is a Javascript object that manages a specific DOM element and descendants. |
|
| 38. |
Explain When You Require Backbone.js? |
|
Answer» Backbone.js is required in following CONDITION:
Backbone.js is required in following condition: |
|
| 39. |
What Are The Three Js Files That You Require To Setup A Working Environment For Backbone? |
|
Answer» you are required following three js files to setup a working environment for BACKBONE
In your application put these files within js FOLDER and USE it in your index.html page you are required following three js files to setup a working environment for backbone In your application put these files within js folder and use it in your index.html page |
|
| 40. |
Why You Have To Use Backbone ? Advantages? |
Answer»
|
|
| 41. |
What Are The Keypoints Of Backbone? |
Answer»
|
|
| 42. |
What Is Backbone Events? |
|
Answer» Backbone events is a module that can be MIXED in to any object, giving the object the ability to bind and trigger custom named events. Events are not DECLARED before they are bound to any object . Events reflects the state of the model. Backbone events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. Events are not declared before they are bound to any object . Events reflects the state of the model. |
|
| 43. |
Explain What Is Backbone.js Router Is Used For? |
|
Answer» When ever an application want to CHANGE their URL FRAGMENT in ORDER to provide bookmarkable and shareable URLs for an AJAX heavy application, backbone.js router is used. When ever an application want to change their URL fragment in order to provide bookmarkable and shareable URLs for an Ajax heavy application, backbone.js router is used. |
|
| 44. |
Explain What Is Backbone.js Collections? |
|
Answer» An ordered SET of models are represented by Backbone.js collections. Any EVENT in model will trigger an event in collection directly. For example, you can bind “CHANGE” event to be notified in a case when any model in the collection has been MODIFIED. An ordered set of models are represented by Backbone.js collections. Any event in model will trigger an event in collection directly. For example, you can bind “change” event to be notified in a case when any model in the collection has been modified. |
|
| 45. |
What Are The Main Components Of Backbone.js ? |
|
Answer» The MAIN COMPONENT of Backbone.js are:
The main component of Backbone.js are: |
|
| 46. |
Explain What Is Backbone.js? |
|
Answer» Backbone.js is a JavaScript client-side (front end) framework, which HELPS to organize your code and makes it easier to develop single PAGE applications. It allows you to structure JavaScript code in an MVC (MODEL, View , Controller) fashion. Model: It is a part of your code that populates and retrieves the data. View: It is the HTML representation of this model. Controller: It enables you to save your javascript APPLICATION via a HASHBANG URl. Backbone.js is a JavaScript client-side (front end) framework, which helps to organize your code and makes it easier to develop single page applications. It allows you to structure JavaScript code in an MVC (Model, View , Controller) fashion. Model: It is a part of your code that populates and retrieves the data. View: It is the HTML representation of this model. Controller: It enables you to save your javascript application via a hashbang URl. |
|