D
D
dtestyk2015-02-15 01:31:46
JavaScript
dtestyk, 2015-02-15 01:31:46

How to make the base object the top level container?

The variant works, but only for the Object itself, not for its descendants. As far as I understand, the behavior I need is implemented by: , but this does not work:Object=documentObject.prototype=window

Object.prototype=window
var a={}
console.log(a.document)
//выведет "undefined"
//должно "#document"

How can such behavior be achieved? If not in the browser, then where is this possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Puzynya, 2015-02-15
@dtestyk

Your goal is achievable in two ways:
The first will allow you to write as you ordered:

var a = {};
console.log(a.document);

but be aware it is dangerous. The thing is, you can't just define window as a prototype for Object - you get circular inheritance - window is an object of type Object, Object is an object of type Window. JS simply won't let you do that, so first let's clear window's memory that it's (a/o) an object
, and now we'll correctly assign the prototype to the object, we'll overwrite its null prototype:
General recipe:
window.__proto__.__proto__.__proto__ = null;
Object.prototype.__proto__.__proto__ = window;

var a = {};
console.log(a.document);

BUT! I would not recommend you to do this, it is very dangerous.
The second option is shorter, safer, but may not suit you:
var a = {__proto__:  window};
console.log(a.document);

It remains only to understand why you needed this at all, perhaps there are much more reliable ways to solve the problem.

B
Barry Allen, 2017-10-15
@B-Allen

There is a special mail function in php for this.
For example:

$mail = mail($yourEmail, $subject, $message,
           "From: ".$name."\r\n"
          ."Reply-To: ".$email."\r\n"
          ."Content-type: text/html; charset=utf-8 \r\n"
          ."X-Mailer: PHP/" . phpversion());

Your mail will never be seen.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question