jquery addClass() 高级应用

<!DOCTYPE html>
<html>
<head>
<style>
div { background: white; }
.red { background: red; }
.red.green { background: green; }
</style>
<script src=”http://code.jquery.com/jquery-latest.js”></script>
</head>
<body>

<div>This div should be white</div>
<div>This div will be green because it now has the “green” and “red” classes.
It would be red if the addClass function failed.</div>
<div>This div should be white</div>
<p>There are zero green divs</p>

<script>
$(“div”).addClass(function(index, currentClass) {
var addedClass;

if ( currentClass === “red” ) {
addedClass = “green”;
$(“p”).text(“There is one green div”);
}

return addedClass;
});
</script>

</body>
</html>

这里的currentClass是单前css
不知道这个function里面的index是什么意思。以后也许会懂吧。看来我js基础不行啊。悲剧。
有没高人给我解释下。。感谢。