js extend prototype
by jiggle
JavaScript
function Test(name){
this.name=name;
};
console.log(Test);
Test.prototype={
outputName:function(){
console.log('Your name is:' + this.name);
}
};
var ext = {
mixIt: function(){
var chars = this.name.split('');
console.log(chars);
var scrambled='';
while (chars.length >1){
var charNum = Math.floor(Math.random() * chars.length);
console.log(charNum);
scrambled +=chars[charNum];
chars.splice(charNum,1);
}
scrambled +=chars[0];
console.log('your scrambled name is:', scrambled);
}
};
$.extend(Test.prototype,ext);
var test = new Test('fred');
test.outputName();
console.log(test.hasOwnProperty('name'));
var test2 = new Test('david');
test2.mixIt();