Pages

Sunday, 19 January 2014

JQuery class with inheritance with constructors


var helper = (function () {
            var alertmsg = function () {
                alert("hi alert1");
            };
            return { ALERTMSG: alertmsg };
        })();

 helper.ALERTMSG()








/** new, preferred syntax **/
   
// properties are directly passed to `create` method
var Person = Class.create({
  initialize: function(name) {
    this.name = name;
  },
  say: function(message) {
    return this.name + ': ' + message;
  }
});
   
// when subclassing, specify the class you want to inherit from
var Pirate = Class.create(Person, {
  // redefine the speak method
  say: function($super, message) {
    return $super(message) + ', yarr!';
  }
});
   
var john = new Pirate('Long John');
john.say('ahoy matey');
// -> "Long John: ahoy matey, yarr!"




No comments:

Post a Comment