My Javascript study notes.
Last active
April 27, 2016 05:42
-
-
Save ericxyan/0af044ad6cf6de12dc954fbccb607718 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Class like object, chaining functions, arguments, setter/getter*/ | |
function SimpleWidget(spec) { | |
var instance = {}; | |
var headline, description; | |
instance.render = function() { | |
var div = d3.select('body').append("div"); | |
div.append("h3").text(headline); | |
div.attr("class", "box") | |
.attr("style", "color:" + spec.color) | |
.append("p") | |
.text(description); | |
return instance | |
}; | |
instance.headline = function(h) { | |
if (!arguments.length) return headline; | |
headline = h; | |
return instance; | |
}; | |
instance.description = function(d) { | |
if (!arguments.length) return description; | |
description = d; | |
return instance; | |
}; | |
return instance; | |
} | |
.append("p") | |
.text(description); | |
return instance | |
}; | |
instance.headline = function(h) { | |
if (!arguments.length) return headline; | |
headline = h; | |
return instance; | |
}; | |
instance.description = function(d) { | |
if (!arguments.length) return description; | |
description = d; | |
return instance; | |
}; | |
return instance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment