Invisible = require("invisible"); crypto = require("crypto"); _s = require("underscore.string"); function Person(firstName, lastName, email){ this.firstName = firstName; this.lastName = lastName; this.email = email; } Person.prototype.fullName = function(){ return this.firstName + ' ' + this.lastName; } Person.prototype.getAvatarUrl = function(){ cleanMail = _s.trim(this.email).toLowerCase(); hash = crypto.createHash("md5").update(cleanMail).digest("hex"); return "http://www.gravatar.com/avatar/" + hash; } module.exports = Invisible.createModel("Person", Person);
Invisible = require("invisible") john = new Invisible.Person("John", "Doe", "john.doe@mail.com"); john.fullName(); //John Doe
<script src="invisible.js"></script> <script> jane = new Invisible.Person("Jane", "Doe", "jane.doe@mail.com"); alert(jane.fullName()); //Jane Doe </script>
Source: https://habr.com/ru/post/206526/
All Articles