Professional Documents
Culture Documents
1.Why is it called a Ternary expression, what does the word "Ternary" indicate?
test ? expression1 : expression2
3.Js Prorotypes
All JavaScript objects inherit the properties and methods from their prototype.
Objects created using an object literal, or with new Object(), inherit from a prototype called
Object.prototype.
4. What is function.prototype.bind
The bind() method creates a new function that, when called, has its this keyword set to the provided
value, with a given sequence of arguments preceding any provided when the new function is called.
EX: this.x = 9;
var module = {
x: 81,
getX: function() { return this.x; }
};
module.getX(); // 81
var getX = module.getX;
getX(); // 9, because in this case, "this" refers to the global object
// Create a new function with 'this' bound to module
var boundGetX = getX.bind(module);
boundGetX(); // 81
Internal use for this:
Function.prototype.bind = function (scope) {
var fn = this;
return function () {
return fn.apply(scope);
};
}
6. What is a closure
That is a closure. A function doesn't have to return in order to be called a closure. Simply accessing
variables outside of your immediate lexical scope creates a closure.
7. Hoisting
http://www.sitepoint.com/back-to-basics-javascript-hoisting/
9.What's the difference between feature detection, feature inference, and using
the UA string?
This is why you see JSONP requests containing the "callback" parameter; so the server knows the name
of the function to wrap the response around.
This function must exist in the global scope at the time the <script> tag is evaluated by the browser (once
the request has completed).
Well, the real power of promises comes from chaining multiple of them together. Calling
promise.then(func) returns a new promise, which is not fulfilled until func has completed. But theres one
really special thing about the way func is used. If a callback supplied to then returns a new promise, then
the promise returned by then will not be fulfilled until the promise returned by the callback is fulfilled
http://www.mattgreer.org/articles/promises-in-wicked-detail/
function Employee() {
this.name = "";
this.dept = "general";
}
function Manager() {
Employee.call(this);
this.reports = [];
}
Manager.prototype = Object.create(Employee.prototype);
Timers allow you to execute code at a set time or repeatedly using an interval. This is accomplished with
the setTimeout, setInterval, and clearInterval functions.Timers can be tricky to use since they operate
within a single thread, thus events queue up waiting to execute.
Load-time errors: The errors shown at the time of the page loading are counted
under Load-time errors. These errors are encountered by the use of improper syntax, and
thus are detected while the page is getting loaded.
Run-time errors: This is the error that comes up while the program is running. It is
caused by illegal operations, for example, division of a number by zero, or trying to access a
non-existent area of the memory.
Logic errors: It is caused by the use of syntactically correct code, which does not
fulfill the required task. For example, an infinite loop.
b. SINGLETON -> Ensure a class has only one instance. Looks just like a module, encapsulated code
within a (function(){})() but has a way of checking if an instance already exists and returns existing
instance.
c. PROTOTYPE -> Specify the kinds of objects to create using a prototypical instance, and create new
objects by copying this prototype.
Create objects which acts as prototype to other objects.
ex: Object.create(vehicle, { data});
e. FACTORY - Provide a generic interface of creating objects and passing different data to them.
Usefull links:
1.http://www.htmlgoodies.com/beyond/javascript/object.create-the-newway-to-create-objects-in-javascript.html
2.https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/Object/create
3.https://developer.mozilla.org/enUS/docs/Web/JavaScript/Guide/Details_of_the_Object_Model
18. Difference between HTML and XHTML
What Is XHTML?
XML is a markup language where documents must be marked up correctly (be "well-formed").
to our <li> elements, we can now display this information instantly without having to worry about making
any Ajax calls and without having to make any server-side database queries.
Prefixing the custom attributes with data- ensures that they will be completely ignored by the user agent.
As far as the browser and indeed the websites end user are concerned, this data does not exist.
As custom data attributes are valid HTML5, they can be used in any browser that supports HTML5
doctypes