Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // class product
- var Product = function(product) {
- //this.title = product.title;
- //this.price = product.price;
- this.id = Object.getPrototypeOf(this).id++;
- };
- // static member - shared between object constructor and inherited in instances
- Product.prototype.id = 0;
- // nethod on class = static method
- Product.unique_id = function() {
- return Product.prototype.id++;
- };
- /* Simple test methods both on instance and static */
- var p1 = new Product();
- var p2 = new Product();
- console.log(p1.id);
- console.log(p2.id);
- console.log("Call 1: " + Product.unique_id() + "// 2");
- console.log("Call 2: " + Product.unique_id() + "// 3");
- console.log("Call 3: " + Product.unique_id() + "// 4");
- /* end of tests */
- var p1 = new Product({
- title: 'Keyboard',
- price: 10500
- });
- //p1.id(); // returns it's id
Advertisement
Add Comment
Please, Sign In to add comment