javascript - Creating object reference in prototype constructor -


i'm trying wrap head around using javascript prototype objects , have run block perhaps due understanding of traditional classes.

my code looks following:

$(document).ready(function () {     var instance = new cards();     $dom = instance.builditem(5); } var cards = function () {     //constructor     this.chromaobj = chroma.scale(["lightblue", "navy"]).domain([2, 6]); } cards.prototype.builditem = function (val) {     var scale = this.chromaobj;     var $item = $("<span>" + val + "</span>").addclass("label-default").addclass("label").css({         "background-color": scale(val)     });     return $item; } 

every time scale called in builditem function, receive error in console scale not function, however, if create scale instance inside of builditem function, works expected.

can please point me in right direction why unable access function reference when defined in constructor?

the original code in fact work correctly.

my problem turned out calling builditem method (not shown here) using generic cards.prototype.builditem(), caused subsequent call chromaobj undefined.

the solution change calls cards.prototype.builditem() this.builditem().


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -