admin管理员组文章数量:1391928
could someone explain to me how the Closure works in more user-friendly form? Its help and documentation leads me nowhere really. How do you perform a simple task such as selecting and modifying the dom (e.g. select all on page and hide them)?
could someone explain to me how the Closure works in more user-friendly form? Its help and documentation leads me nowhere really. How do you perform a simple task such as selecting and modifying the dom (e.g. select all on page and hide them)?
Share Improve this question edited Oct 3, 2010 at 17:41 skaffman 404k96 gold badges824 silver badges775 bronze badges asked Oct 3, 2010 at 17:38 user2033475user2033475 1- @DavidAnderson Sorry about that! It got closed as a duplicate and I didn't think someone else would e. Thank you for answering here! I've reopened it in the meantime and updated it because I finally found a way around the problem. No weird Windows apps involved. I appreciate it still. – user2033475 Commented Jun 28, 2023 at 16:27
2 Answers
Reset to default 7See http://derekslager./blog/posts/2010/06/google-closure-introduction.ashx, Comparison #4,
Hide all div
's:
<html>
<head>
<script src="http://closure-library.googlecode./svn/trunk/closure/goog/base.js" type="text/javascript"></script>
<script language="JavaScript">
goog.require('goog.dom.query');
goog.require('goog.style');
</script>
<script>
function HideElement(selector) {
goog.array.map(goog.dom.query(selector, null), function(e) {
goog.style.showElement(e, false);
});
}
</script>
</head>
<body>
<div>div</div>
<p>paragraph</p>
<div>another div</div>
<input type="button" value="hide" onclick="HideElement('div');"/>
</body>
</html>
Can't help you with the user-friendly breakdown, though.
I thought the API docs were really great at first, but after writing a few hundred lines of code I've run into all kinds of quirks and problems. For instance the dom module documentation doesn't have a clear entry point for discovering dom manipulation methods -> all the top-level links are to helper objects it uses internally. You can find some useful methods though if in the package reference list you click dom, then DomHelper. It seems like you need to instantiate a DomHelper to get access to those tools though?
Luckily they did include handy links into the code all over the API docs. If you poke around in the DomHelper source you'll see that most of the listed methods are available directly from the goog.dom namespace!
My other major gripe is that the docs often don't list argument types/names/descriptions. For instance if you expand goog.dom.DomHelper.contains it doesn't list any arguments, but the code correctly annotates two args. I can't believe they made such a thoroughly annotated and documented library and then failed to include that information in the (generated) docs! Although while browsing their code you will often find terse and uninformative ments in their annotations too.
So, to summarize: read the code! I always hate hearing that answer but it seems to be the best option right now.
I have the O'Reilly Closure book too, and although it does provide some insights it still isn't very in-depth on actually using basic patterns and tools provided in the library. I would really like a better over-view of how parts of the library are intended to interact. I guess someone should make a closure-tools cookbook?
本文标签: javascriptconfusing google closure library apiStack Overflow
版权声明:本文标题:javascript - confusing google closure library api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744697066a2620341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论