Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改善对于多宿主环境的支持,增加 strict 模式 #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions baiduTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
* @email 1988wangxiao@gmail.com
*/

;(function(window){

//取得浏览器环境的baidu命名空间,非浏览器环境符合commonjs规范exports出去
//修正在nodejs环境下,采用baidu.template变量名
var baidu = typeof module === 'undefined' ? (window.baidu = window.baidu || {}) : module.exports;
;(function(root, factory) {
if (typeof exports === 'object') {
module.exports = factory();
}
else if (typeof define === 'function' && define.amd) {
define([], factory);
}
else {
root['baidu'] = factory();
}
}(this, function() {

"use strict";

var baidu = {};

//模板函数(放置于baidu.template命名空间下)
baidu.template = function(str, data){
Expand All @@ -23,7 +33,7 @@
var fn = (function(){

//判断如果没有document,则为非浏览器环境
if(!window.document){
if(typeof document !== 'object'){
return bt._compile(str);
};

Expand Down Expand Up @@ -213,4 +223,6 @@
return str;
};

})(window);
return baidu;

}));