Category: iOS-based development
-CAchieve integration java scrip code below:
/ / Inherited
function Person (name, sex)
{
this.name = name;
this.sex = sex;
}
Person.prototype.sayName = function ()
{
alert (this.name);
}
Person.prototype.saySex = function ()
{
alert (this.sex);
}
function Worker (name, sex, job)
{
/ / Inherits person class
Person.call (this, name, sex) / / Here is an example of this refers to the Worker class, as shown in the 'W', the W incoming Person constructor, then W disguised Person constructor of this < br />this.job = job;
}
/ / Worker.prototype = Person.prototype ;/ / if so negative prototype, sayJob parent class method Person subclass will have sayJob method, because it is passed by reference
/ / Into the following sub-class will not affect the way the parent class:
for (var i in Person.prototype)
{
Worker.prototype [i] = Person.prototype [i];
}
Worker.prototype.sayJob = function ()
{
alert (this.job);
}
var p = new Person ('lisi', 'M');
/ / Alert (p.sayJob);
var w = new Worker ('zhangsan', 'M', 'soy sauce');
w.sayName ();
w.saySex ();
w.sayJob ();
Tags: java JavaScript
Reply:
You said that category?
https://developer.apple.com/library / ios / documentation / cocoa / conceptual / ProgrammingWithObjectiveC / CustomizingExistingClasses / CustomizingExistingClasses.html
Reply:
This is the Blue Gull school teacher, I have the impression. Always support the Blue Gull!
No comments:
Post a Comment