Skip to content

Instantly share code, notes, and snippets.

@ericxyan
Last active April 27, 2016 05:42
Show Gist options
  • Save ericxyan/0af044ad6cf6de12dc954fbccb607718 to your computer and use it in GitHub Desktop.
Save ericxyan/0af044ad6cf6de12dc954fbccb607718 to your computer and use it in GitHub Desktop.
/* 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;
}

My Javascript study notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment