function Class() {}
// Helper function to correctly set up the prototype chain for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and
// class properties to be extended.
Class.extend = function(protoProps, staticProps) {
var parent = this, child, prop;
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent constructor.
if (protoProps && protoProps.hasOwnProperty('constructor')) {
child = protoProps.constructor;
} else {
child = function() { return parent.apply(this, arguments); };
}
// Add static properties to the constructor function, if supplied.
for (prop in parent) child[prop] = parent[prop];
for (prop in staticProps) child[prop] = staticProps[prop];
// Set the prototype chain to inherit from `parent`, without calling
// `parent` constructor function.
var Surrogate = function() { this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
// Add prototype properties (instance properties) to the subclass,
// if supplied.
for (prop in protoProps) child.prototype[prop] = protoProps[prop];
// Save parent prototype
child.prototype.__super__ = parent.prototype;
return child;
};
var Model = Class.extend({
constructor: function() {
console.log("Model:constructor()");
}
});
var User = Model.extend({
constructor: function() {
this.__super__.constructor();
console.log("User:constructor()");
}
});
var SuperUser = User.extend({
constructor: function() {
this.__super__.constructor();
console.log("SuperUser:constructor()");
}
});
var supeUser = new SuperUser();
// Wait for device API libraries to load
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
readDataUrl(file);
readAsText(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
};
reader.readAsText(file);
}
function fail(error) {
console.log(error.code);
}
// Wait for device API libraries to load
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample text'");
writer.truncate(11);
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample'");
writer.seek(4);
writer.write(" different text");
writer.onwriteend = function(evt){
console.log("contents of file now 'some different text'");
}
};
};
writer.write("some sample text");
}
function fail(error) {
console.log(error.code);
}
site.get_discount_price = function(discount_id, callback) {
jQuery.ajax({
url: '/test.php/' + discount_id + '.json',
dataType: 'json',
success: function (data) {
if (callback) callback(data.summa_vozvrata);
}
});
}
/* ... */
site.get_discount_price(discount_id, function(summa) {
/* и уже здесь мы работаем с переменной summa */
});