Time Management

Last year, I translated the book The Future of the Mind by Michio Kaku. However, I got tangled up with some other translation jobs (no less than 4 big books for clients) and I couldn’t get to contact a publisher for publishing it. Long story short, several translators published their translations of this book. Finally, when I did get to preparing my work, it was too late already.

Now I am translating a part of the 20th edition of Nelson and I fear the same will happen again. Because, guess what, I am once again tangled up with a lot of work. I have to do something about this. My time management is terrible.


کسب اجازه از انتشارات اورایلی برای انتشار کتاب «مرجع برنامه‌نویسی جاوا اسکریپت» در ایران

من در ایمیلی از انتشارات اورایلی خواسته بودم که اجازه‌ی انتشار ترجمه‌ی فارسی ویراست سوم کتاب مرجع جیبی جاوا اسکریپت را که با عنوان «مرجع برنامه‌نویسی جاوا اسکریپت» منتشر خواهد شد، به من بدهند. خوشبختانه، امروز ایمیلی از اورایلی دریافت کردم که در آن اجازه‌ی ترجمه و انتشار این کتاب در ایران داده شده است. بخش‌هایی از این ایمیل به قرار زیر است:
Dear Ghasem,
Thanks very much for contacting us regarding your interest in a Persian translation of JavaScript Pocket Reference, 3rd Edition by David Flanagan.
We are happy to grant you permission to translate and publish a Persian edition of that book, and to distribute the Persian edition […] within Iran […]
We are grateful for the support and enthusiasm of readers like you, and we look forward to hearing from you again […]
شایان ذکر است که کتاب مذکور ان‌شاءالله تا یکی دو هفته‌ی دیگر منتشر خواهد شد.


A curious observation about the calendar

The current time in Java internal representation (denoting the number of milliseconds since midnight of 1970-01-01) is 1392051911984 and the current solar Hijri (Iranian) date (using the format "yyyymmdd") is 13921121. This is the last day where the first eight digits of the former constitute a number that is smaller than the latter. This situation will not happen again in the next couple of centuries.


مرجع برنامه‌نویسی جاوا اسکریپت

ترجمه‌ی ویراست سوم کتاب «مرجع جیبی جاوا اسکریپت» آماده شده است و به امید خدا به زودی منتشر می‌شود. با توجه به اینکه کتاب در قطع رقعی منتشر می‌شود، عنوان مرجع جیبی برای آن مناسب نیست و لذا کتاب با عنوان «مرجع برنامه‌نویسی جاوا اسکریپت» منتشر خواهد شد.


Property Assignment and hasOwnProperty

An important task in JavaScript development is to check if a property has already been assigned a value. There are two ways to check for the presence of a property in an object. The first method, prop in obj, checks the existence of the property in the object or in its prototype chain. The second method, obj.hasOwnProperty(prop), checks if the property exists on the object itself.

If a property exists on the object’s prototype, it is masked by an assignment of that property on the object itself. Consider the following code snippet:

(function () {
 var p = {
  name : "human",
 var a = Object.create(p);
 console.log(a.name); // human
 console.log(a.hasOwnProperty("name")); // false
 a.name = "Ali";
 console.log(a.name); // Ali
 console.log(a.hasOwnProperty("name")); // true

Noting these results, it would seem appropriate to use hasOwnProperty as a test for checking whether the property has been assigned a value on the object proper. But this leads to an unexpected result in the particular case of “accessor” properties:

(function () {
 var p = Object.defineProperties({
   _age : 0,
  }, {
   _age : {
    enumerable : false,
   age : {
    get : function () {
     return this._age;
    set : function (age) {
     if (isNaN(age) || (age < 0)) {
      throw new Error("Invalid value for age: " + age);
     this._age = age;
    enumerable : true,
    configurable : true,
 var a = Object.create(p);
 console.log(a.age); // 0
 console.log(a.hasOwnProperty("age")); // false
 a.age = 14;
 console.log(a.age); // 14
 console.log(a.hasOwnProperty("age")); // false

This example shows that “accessor” properties of the prototype are not masked by value assignment on the descendent object. Consequently, hasOwnProperty cannot detect value assignment in these cases.


Inheritance in JavaScript

JavaScript makes heavy use of objects, but its inheritance pattern is not like other object-oriented languages. Rather than class-based inheritance, JavaScript uses prototype-based inheritance. Objects are created by calling constructor functions with the new keyword. Every function has a prototype property that points to a prototype object. Any object instance has an implied reference to its prototype object (which may be null as well). Since the prototype is itself an ordinary object, it has a prototype too. This is what is called the prototype chain. When accessing a property of an object, the JavaScript engine tries to locate that property on the object itself. If it is not found on the object, it is searched in its prototype object and so forth.

The following code shows a simple example of using prototype-based inheritance.

var Shape = function () {};
Shape.prototype = Object.create(Object.prototype);
Shape.prototype.area = function () {
    throw new Error("Not implemented");

var Rectangle = function (width, height) {
    this.width = width;
    this.height = height;
Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.area = function () {
    return this.width * this.height;

var Square = function (side) {
    Rectangle.apply(this, [side, side]);
Square.prototype = Object.create(Rectangle.prototype);

var square = new Square(16);
console.log(square.area()); // prints 256


The Sales Success Handbook

A few years ago, I had been asked by Adineh Publishing House to translate a book entitled The Sales Success Handbook by Linda Richardson. Recently, I noticed that the book has been published. If you are interested, you can order it online from adinebook.com.

چند سال قبل، مدير محترم انتشارات آدينه از من درخواست كرد كه كتاب موفقيت در فروش نوشته‌ي ليندا ريچاردسون را ترجمه كنم. اخيراً متوجه شدم كه كتاب چاپ شده است. اگر علاقه‌مند باشيد، مي‌توانيد كتاب را از adinebook.com سفارش دهيد.