如何在javascript中将我的快捷语言中的文档设置为d? [英] How can I set document in my shortcut language as d in javascript ?

查看:64
本文介绍了如何在javascript中将我的快捷语言中的文档设置为d?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为javascript创建一个快捷语言,我厌倦了那些漫长的驼峰案例方法,所以这里我想把文件作为d。



我有什么试过:



Object.prototype.d = function()

{

文件。这个;

};



d.write(你好);



/ *我想要d.write(hello);而不是document.write(hello); * /

i m creating a shortcut language for javascript, i m tired of those long camel case method, so here i want document as d.

What I have tried:

Object.prototype.d = function ()
{
document.this;
};

d.write("hello);

/* i want d.write("hello"); instead of document.write("hello"); */

推荐答案

试试这个



try this

var d = document;
 d.write("hello");  


您正在引用 document.this ,而不是文档本身。你所拥有的对象没有写的定义。所以不要这样,试试这个:

You are referencing document.this, not document itself. And the object you are having does not have a definition for "write". So instead of that, try this:
var d = document;
d.write("Hello, world!");



在此尝试:编辑小提琴 - JSFiddle [ ^ ]。


这篇关于如何在javascript中将我的快捷语言中的文档设置为d?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆