Basic Sproutcore: class method, class variables help -
this how defining simple class instance variables , instance methods.
exampleclass = sc.object.extend({ foo:undefined, bar: function() { this.foo = "hello world"; console.log( this.foo ); } } // test var testinstance = exampleclass.create(); testinstance.bar(); // outputs 'hello world'
could me out similar example of class variable (or similar behavoir), , class method?
thanks
a class method/property done like:
exampleclass = sc.object.extend({ foo:undefined, bar: function() { this.foo = "hello world"; console.log( this.foo ); } } exampleclass.mixin({ classfoo: "foo", classbar: function() { return "bar"; } })
then can access like:
exampleclass.classfoo
but don't forget when accessing property (or computed property) on instance, need use .get()
like:
var example = exampleclass.create(); // example.get('foo'); example.set('foo', 'baz'); // bad!! don't this, or bindings/ observes won't work. example.foo; example.foo = 'baz';
Comments
Post a Comment