Anubhav Tiwari Anubhav Tiwari - 3 months ago 15
Javascript Question

Why is the function undefined?



(function(window){
var devigner = window.devigner = {};
devigner.create = function() { /*a generic method to create elements */
var element = function() {

};
};
})(window);





The above code has an error for document.create.element being undefined while the typeof devigner is object which is correct , but typeof devigner.create is function.

when run in firebug

Answer

You need to do the function:

document.create().element

Also, create function should return an object with an 'element' value

create = function() {
    var element = ....
    ....
    return {element: element}
}