var someComponent = ( function () {
var self = this ;
// Methods
this .method1 = function () {
}
this .method2 = function () {
}
this .method3 = function () {
}
// Constructor
this .prop1 = 'foo' ;
this .prop2 = 'bar' ;
this .prop3 = 'qaz' ;
return this ;
})();
* This source code was highlighted with Source Code Highlighter .
var periodInfo = ( function (sportKind) {
var self = this ;
this .sportKind = sportKind || 'football' ;
this .hintBox = null ;
this .hintBoxTop = null ;
this .hintBoxLeft = null ;
this .inputElement = null ;
this .currentPeriod = 1;
/**
* Show panel.
*/
this .show = function () {
$( '#goals-panel' ).show();
}
/**
* Hide panel.
*/
this .hide = function () {
$( '#goals-panel' ).hide();
}
/**
*
*/
this .clear = function () {
$( '[class~="home"]' ).remove();
$( '[class~="away"]' ).remove();
}
$( document ).ready( function () {
// .
self.hintBox = $( '#hint-box' );
$( document ).click( function () {
self.hide_hint_box();
});
});
return this ;
})();
* This source code was highlighted with Source Code Highlighter .
function Person(firstname, lastname, age) {
var self = this ;
// Assign values to private members.
var firstname = firstname;
var lastname = lastname;
var age = age || 'unknown' ;
// Private method.
this .name_fix_up = function (name) {
return name[0].toUpperCase() + name.substr(1);
}
// Public methods.
return {
get_age: function () {
return age;
},
get_name: function () {
return self.name_fix_up(firstname) + ' ' + self.name_fix_up(lastname);
}
}
}
var p = new Person( 'vasya' , 'pupkin' , 23);
alert( "It's " + p.get_name() + ', he is ' + p.get_age() + ' years old.' )
// Trying to access private method.
p.name_fix_up( 'sergey' );
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/91645/
All Articles