JavaScript LAB

//'use strict';

function inherit(object) { if (object == null) { throw TypeError(); }

if (Object.create) {
    Object.create(object);
}

var type = typeof object;

if (
    type !== 'object'
    && type !== 'function'
) {
    throw TypeError();
}

function f() {}

f.prototype = object;

return new f();

}

//function testStrictMode() { // console.log('TEST STRICT MODE. this:'); // // В строгом режиме this = undefined. // // В нестрогом режиме this = window. // console.log(this); //}

//testStrictMode();

//var obj1 = {r: 1}; //var obj2 = inherit(obj1); // //obj2.x = 1; obj2.y = 2; //obj2.r = 3; //obj2.desc = 'new circle';

//console.log(obj1.r); //console.log(obj2.r);

//var teststr = 'qwerty'; //console.log(teststr.length);

//var y = obj2.descr.length; //console.log(y); // => Uncaught TypeError: Cannot read property 'length' of undefined

//var parent = {x: 1}; //var child = {y: 2}; //child.prototype = parent;

//for (prop in child) { // console.log(prop); //}

//var len1 = obj2 && obj2.desc && obj2.desc.length; //var len2 = obj2 && obj2.descr && obj2.desc.length; //console.log(len1); // => 10 //console.log(len2); // => undefined, но не TypeError

//var acc = { // _login: '', //get login() {return this._login;}, //set login(value) {this._login = value;}, // x: 1 //};

//console.log(acc.login); // => 'test' //console.log(acc.login = 'test2'); // (non strict mode) => 'test2', но свойство login не поменяется! //console.log(acc.login); //console.log(acc.login = 'test2'); // (strict mode) Uncaught TypeError: Cannot set property login of #

Оценка статьи 0

Комментарии

Пока комментариев нет.