0

I'm new to the world of javascript. I'm used to strictly typed languages, however I'm trying to get into javascript and jquery. Imagine I have a large set of scripts or functions and I want to avoid the use of anonymous classes. Is there an elegant way to enforce that parameter 'e' needs to be a 'div' object or some JQuery version of that?

var CORE = {
    onReady: function(){
        $("#generate").click(ELEM.genClick($("#quote")))
    },
    //...
};

var ELEM = {
     genClick: function(e){
         // e must be div!
     },
     //...
};

$(document).ready(CORE.onReady());
4

1 に答える 1

3

チェックeは次の<div>とおりです。

e instanceof HTMLDivElement // implies e instanceof HTMLElement
// OR
e.nodeType === 1 && e.tagName === 'DIV'
于 2013-08-27T19:10:49.203 に答える